我有将数据绑定到指令的这个奇怪的问题。这是我声明我的指令:在指令中绑定数据会返回不一致的值
<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