Check if an object has a property [duplicate]
The problem is that you probably will have value not just when linking your directive - it could be loaded by $http for example.
My advice would be:
controller: function($scope) { $scope.$watch('test.hello', function(nv){ if (!nv) return; // nv has the value of test.hello. You can do whatever you want and this code // would be called each time value of 'hello' change });}
or if you know that the value is assigned only one:
controller: function($scope) { var removeWatcher = $scope.$watch('test.hello', function(nv){ if (!nv) return; // nv has the value of test.hello. You can do whatever you want removeWatcher(); });}
This code will remove watcher the value of 'test.hello' was assigned (from any controller, ajax, etc etc)