为什么我的外部模板不使用ng-repeat
呈现项目?指令模板中的ng-repeat AngularJS
--- AngularJS 1.1.5
我偶然在this bug,但我不知道这是否是同样的问题?如果有任何解决方法?
这是Plunker使用静态列表,但解决方案需要支持双向绑定,因为数据是动态的。 (这就是它是如何应该反正工作...)
控制器
.controller('main', ['$scope',function($scope) {
$scope.items = ['a','b','c'];
}])
指令
.directive('items', function() {
return {
restrict: 'E',
replace: true,
controller: 'main',
templateUrl: 'items.html',
link: function(scope, controller) {
}
};
})
items.html
<div ng-repeat="item in items">
{{item}}
</div>
作品对我来说分叉的plunkr ..奇怪了。 – Florian
+1 Thankyou就是这样。我想知道为什么你需要用根元素来包装。 –
我在主题上扩展了我的答案。 – Florian