我有將數據綁定到指令的這個奇怪的問題。這是我聲明我的指令:在指令中綁定數據會返回不一致的值
<my-directive data="myArray"></my-directive>
我的指令代碼如下所示:
angular.module('ngApp')
.directive('myDirective', function() {
return {
scope:{
data: '='
},
template: '<div steps="data.length"></div>',
restrict: 'E',
link: function postLink(scope, element, attrs) {
console.log(scope);
console.log(scope.data);
}
};
});
中的第一個日誌,數據屬性是正確的: screenshot of console.log output 但second log是不確定的。
有什麼想法爲什麼?
你能提供一個JSFiddle或Plunkr來演示這個問題嗎? – Matheno