Làm thế nào để bạn thiết lập giá trị phạm vi cho một cái gì đó như thế này:Làm thế nào để bạn truy cập một mục ng-lặp lại trong phạm vi của chỉ thị?
<div ng-controller="MyCtrl">
<my-element ng-repeat="p in people" person='p'></my-element>
</div>
var myApp = angular.module('myApp',[]);
myApp.directive('myElement', function(){
return {
restrict: 'E',
template: '<div>{{ name }}</div> <div>{{ age }}</div>'
}
});
function MyCtrl($scope) {
$scope.people = [{ name: 'Mike', age: 20 },{name: 'Peter', age: 22 }];
}
là dạng này 'ng-repeat =" p trong người "person = 'p'' vẫn hợp lệ. Tôi không thấy nó được đề cập trong tài liệu và đưa ra lỗi cho tôi. cảm ơn – bsr
@bsr, nó phải hợp lệ: [làm việc fiddle] (http://jsfiddle.net/mrajcok/xgxQJ/) –
cảm ơn Mark cho fiddle – bsr