Angular.js 指令模板:换行
Angular.js directive template: break line
假设我有这个演示指令:
app.directive('name', function(){
return{
restrict: 'E',
template: '<div ng-class="done" ng-click="doSomething(data.done, index)">{{data.text}}<button ng-click="remove(index)">delete</button></div>'
}
});
是否可以只打断模板的字符串,还是应该在每行的末尾添加“+”或其他内容?
例如-
app.directive('name', function(){
return{
restrict: 'E',
template: '<div ng-class="done" ng-click="doSomething(data.done, index)">
{{data.text}}
<button ng-click="remove(index)">delete</button>
</div>'
}
});
谢谢:)
您不能在单引号中换行而不会出错。您可以使用双引号,但不建议在严格的 JavaScript 模式下使用。可能最好每行使用一个字符串,最后加上一个 +,创建结果
双引号注意事项:
line breaks using javascript strings
如果模板要变得更复杂,最好使用 templateUrl。
假设我有这个演示指令:
app.directive('name', function(){
return{
restrict: 'E',
template: '<div ng-class="done" ng-click="doSomething(data.done, index)">{{data.text}}<button ng-click="remove(index)">delete</button></div>'
}
});
是否可以只打断模板的字符串,还是应该在每行的末尾添加“+”或其他内容? 例如-
app.directive('name', function(){
return{
restrict: 'E',
template: '<div ng-class="done" ng-click="doSomething(data.done, index)">
{{data.text}}
<button ng-click="remove(index)">delete</button>
</div>'
}
});
谢谢:)
您不能在单引号中换行而不会出错。您可以使用双引号,但不建议在严格的 JavaScript 模式下使用。可能最好每行使用一个字符串,最后加上一个 +,创建结果
双引号注意事项: line breaks using javascript strings
如果模板要变得更复杂,最好使用 templateUrl。