我試圖用NG-重複指令中的模板是這樣的:NG重複不會工作
JS
var module = angular.module("myModule", []);
module.directive('direct', function()
{
return {
restrict: 'E',
controller: "directController",
// This HTML will replace the direct directive.
replace: true,
transclude: true,
scope: {title: "@"},
template:
'<div>'
// print: this is a title, which is correct
+ '{{title}}'
+ '<br>'
// print: ["1","2","3"], which is correct
+ '{{list}}'
+ '<br>'
// doesn't print anything, why ?!
+ '<div ng-repeat="l in list">{{l}}</div>'
+ '</div>',
link: function (scope, element, attrs, controller)
{
// scope has list in it
console.log(scope);
}
}
});
module.controller('directController', ["$scope", function ($scope)
{
$scope.list = ["1", "2", "3"];
}]);
angular.bootstrap($('html'),['myModule']);
HTML
<direct title="this is a title"></direct>
結果HTML
<div>
this is a title
<br>
["1","2","3"]
<br>
</div>
如上所示,ng-rep吃不打印'列表', 打印列表或記錄它,它工作正常,爲什麼:(?
更新:
的問題是使用的角度引導功能註冊模塊,因爲我沒有使用ng-app="myModule"
指令。
如果我使用ng-app="myModule"
指令或注入var module = angular.module("ng");
模塊它應該做的伎倆。
你有'
'下'{{列表之後未封閉的串} }' –
對不起,這是打字錯誤,但這不是問題。 – Ayman