【发布时间】:2013-12-09 08:04:51
【问题描述】:
我在将对象信息传递给具有隔离范围的自定义指令时遇到问题。我把我的问题归结为这个简单的 plnkr 来演示我正在撞墙:
http://plnkr.co/edit/oqRa5pU9kqvOLrMWQx1u
我只是错误地使用了 ng-repeat 和指令吗?同样,我的目标是将对象信息从 ng-repeat 循环传递到我的指令中,该指令将具有自己的范围。
HTML
<body ng-controller="MainCtrl">
<ul>
<li ng-repeat="i in items", my-directive="i">
<span>{{$index}}</span>
<p>{{item.name}}</p>
<p>{{item.value}}</p>
</li>
</ul>
</body>
JS
var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope) {
$scope.items = [
{name: "Name #1", value: "Value #1"},
{name: "Name #2", value: "Value #2"},
{name: "Name #3", value: "Value #3"}
];
});
app.directive('myDirective', function($scope) {
return {
restrict: "A",
scope: { item: "=myDirective" },
link: function(scope, elem, attrs) {
}
}
});
谢谢。
【问题讨论】:
标签: angularjs angularjs-directive angularjs-scope angularjs-ng-repeat