1
我想給value
從ng-repeat
directive
獲取得到的值,但只有我被$index
安慰的value
控制檯爲undefiend
。無法從`directive`範圍
這裏有什麼問題?
我的代碼:
HTML:
<body ng-controller="main">
<h1>{{index}}</h1>
<new-array index='$index' ng-repeat="value in values">{{value}}</new-array>
</body>
JS:
var myApp = angular.module('myApp', []);
myApp.controller('main', function ($scope) {
$scope.values = [{"name":"one", "num" : 1}, {"name":"two", "num" : 2}, {"name":"three", "num" : 3}]
$scope.index = 0;
$scope.update = function (num) {
$scope.index = num;
}
});
myApp.directive("newArray", function() {
return {
scope : {
value : "=",
index : "="
},
link : function (scope, element, attrs) {
console.log(scope.value, scope.index)
//reusult as "undefined" 1
}
}
})