Я пытаюсь создать директиву с областью выделения.
у меня есть
angular.module('myApp').directive('itemCollection',
['$cookies',
function($cookies) {
return {
restrict: 'E',
scope: {
items: '='
},
link: function(scope) {
console.log(scope.items)
console.log(items)
--> both console.log show undefined
}
};
}
]);
Html
<item-collection items="item1"></item-collection>
Кажется, я не могу получить 'item1'
в моей директиве, и он не определен. Я не уверен, что мне не хватает. Может ли кто-нибудь мне помочь? Благодарю!
item1
ли item1
асинхронно? Если это так, вам нужно настроить часы в своей директиве и процессе, как только он будет доступен.
return {
restrict: 'E',
scope: {
items: '='
},
link: function(scope) {
console.log(scope.items)
console.log(items)
--> both console.log show undefined
scope.$watch(
function() { return scope.items; },
function(newValue) {
if (newValue != null) {
console.log('not null:' + newValue);
}
else {
console.log('still null, skip');
}
}
);
}
};
item1
настроен на что-либо в вашей родительской области?