私はこのフィドルを持っています
angular.module('mainApp', [])
.directive('list', function factory() {
return {
restrict: 'E',
scope: {
size: '=',
listWidth: '@'
},
replace: true,
template: '<ul class="syn-list"><li ng-repeat="item in items">{{item}}</li></ul>',
link: function(scope, element, attrs) {
scope.items = ['item 1', 'item 2', 'item 3'];
$('#p1').html(scope.size + ' - ' + attrs.size + ' :: ' + scope.listWidth + ' - ' + attrs.listWidth);
setTimeout(function() {
$('#p2').html(scope.size + ' - ' + attrs.size + ' :: ' + scope.listWidth + ' - ' + attrs.listWidth);
}, 0);
}
};
});
scope.size が期待値に設定され、scope.listWidth が undefined を返すのはなぜですか?
そして、0 秒の setTimeout 呼び出し内で scope.listWidth が期待値に設定されるのはなぜですか?