Note that there are some explanatory texts on larger screens.

plurals
  1. POAngularjs event and asynchronous module load
    primarykey
    data
    text
    <p>I have an issue with my angularjs app on the events and listeners.</p> <p>My application has an index.html file like this:</p> <pre><code>&lt;body ng-app="ua.myApp"&gt; &lt;!-- Navigation bar --&gt; &lt;ng-include src="'app/common/navbar/navbar.tpl.html'"&gt;&lt;/ng-include&gt; &lt;ng-view&gt;&lt;/ng-view&gt; &lt;script type="text/javascript" src="app/common/navbar/navbar.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="app/part1/part1.js"&gt;&lt;/script&gt; &lt;/body&gt; </code></pre> <p>In the navbar controller I have a listener:</p> <pre><code>console.log('Setup event listner - navBar: update'); $scope.$on('navBar: update', function() { if (uaContext.loginStatus.get() == true) { $scope.setLoggedInBar(); } else { $scope.setLoggedOutBar(); } }); </code></pre> <p>And in the part1 app I broadcast an event:</p> <pre><code>function ($scope, $rootScope, $routeParams, uaContext) { console.log('Send event listner - navBar: update'); $scope.$on('$routeChangeSuccess', function () { uaContext.productId.set($routeParams.productId); uaContext.appName.set('part 1'); $rootScope.$broadcast('navBar: update'); }); } </code></pre> <p>The dependencies in myApp are in this order:</p> <pre><code>var myApp = angular.module('ua.myApp', [ 'ua.NavBar', 'ua.Part1']); </code></pre> <p>It's working fine. Console log:</p> <pre><code>Setup event listner - navBar: update (nav_bar.js) Send event listner - navBar: update (part1.js) </code></pre> <p>The issue is that sometimes the event is sent by part1 app before the listener in navbar is operational. So we get this situation: </p> <pre><code>Send event listner - navBar: update (part1.js) Setup event listner - navBar: update (nav_bar.js) </code></pre> <p>Thus the nav bar is not updated.</p> <p>Do you know how I can fix this issue? Maybe I can emit the event in another event than <strong>routeChangeSuccess</strong> but I didn't found the documentation on the events.</p> <p>Thank you</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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