Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The problem is: at that time angular <strong><em>does not update its bindings</em></strong> yet. </p> <p>You should not access your variables like this, try to use angular js binding mechanism to bind it to <strong><em>view</em></strong> (by using $watch for example). Binding to parent scope variables means you're <strong><em>passive</em></strong>, just listen for changes and update <strong><em>other variables</em></strong> or <strong><em>your view</em></strong>. That's how we should work with angular.</p> <p>If you still need to access it. You could try a workaround using $<a href="http://docs.angularjs.org/api/ng.%24timeout">timeout</a></p> <pre><code>$scope.setDefaults = function() { $timeout(function () { alert(JSON.stringify($scope.appSubs)); //Coming as undefined },0); }; </code></pre> <p><a href="http://jsfiddle.net/hsGnC/">DEMO</a></p> <p>It's better to use $watch</p> <pre><code> angular.module('ctrl', []).controller('TempCtrl', function ($scope, $location, $rootScope) { $scope.appSubscriptions = "Subscriptions"; $scope.appObj = "Objs"; $scope.showAppEditWindow = function () { //Binding the directive isolate scope objects with parent scope objects $scope.asAppObj = $scope.appObj; $scope.asAppSubs = $scope.appSubscriptions; }; }); angular.module('ctrl').directive('tempDirective', function () { return { restrict: 'E', replace: true, scope: { appObj: '=asAppObj', appSubs: '=asAppSubs' }, link: function (scope, element, attrs) { }, controller: function ($scope, $timeout) { $scope.$watch("appSubs",function(newValue,OldValue,scope){ if (newValue){ alert(JSON.stringify(newValue)); } }); }, template: "&lt;div&gt;{{appSubs}}&lt;/div&gt;" }; }); </code></pre> <p><a href="http://jsfiddle.net/hsGnC/1/">DEMO</a></p> <p>By using $watch, you don't need to broadcast your event in this case.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload