When my "AngularJS" page loads, I retrieve some data from the server and set it to the scope:
myApp.controller('somePage', ['$scope', 'User', '$routeParams', function($scope, User, $routeParams){ // Get the user. User.get('1234').then(function(user){ $scope.user = user; }); });
On my page, I have a directive that needs the definition of $scope.user .
<div> <user-profile-info></user-profile-info> </div>
Directive:
myApp.directive('addActionButton', function() { return { scope: false, link: function(scope, element, attrs){ element.bind('click', function(){ alert(scope.user.name); }); }, template: '<button id="foo">Say hi to {{ user.name }}</button>' }; })
The page currently displays the component up to $scope.user , so there are errors.
How can I make this directive only render when $scope.user ? Or how can I make a page view only rendering when the controller receives its data?
EDIT: all of the above code is greatly simplified, so you do not need to read additional information, but still there are restrictions that I need for the component (for example, a link, a template with an attribute, an area with ajax call).