В моей настраиваемой директиве мне нужно получить доступ к объекту $ scope. $ Parent.users.
Если я console.log $ scope. $ Parent:
pillbox_directives.directive('scheduleCell', function(){
return {
restrict: 'EA',
link: function($scope, element, attrs){
console.log($scope.$parent);
}
}
});
... тогда запрашивается искомый $ parent, и он содержит объект "пользователи", как и ожидалось:
$$ChildScope: function b() {this.$$watchers=this.$$nextSibling=this.$$childHead=this.$$childTail=null;this.$$listeners={};this.$$listenerCount={};this.$$watchersCount=0;this.$id=++ob;this.$$ChildScope=null;}
$$childHead: n
$$childTail: n
$$listenerCount: Object
$$listeners: Object
$$nextSibling: null
$$prevSibling: null
$$watchers: Array[4]
$$watchersCount: 0
$id: 2
$parent: n
cloneDrop: function ($index) {
deadDrop: function ($index) {
generateSchedule: function (day) {
logOff: function () {
notSorted: function (obj) {
setup: Array[2]
users: Array[2]
__proto__: n
Однако, если я console.log($ scope. $ Parent.users), он регистрирует 'undefined'
Любые идеи относительно того, почему я не могу получить доступ к $ scope. $ Parent.users таким образом?
Массив пользователей заполняется вызовом $ http.get от контроллера и не был заполнен к тому времени, когда директива попыталась выполнить console.log($ scope. $ Parent.users)
Решением было добавить ng-if = "users" в элемент директивы, чтобы гарантировать, что "пользователи" существуют и загружаются до загрузки директивы.