1

I have a view as

 <div class="wrapper" ui-view>
        @RenderBody()
    </div>

And the state that renderes a template called _BodyLayout is

(function () {
    angular.module('ngApp').config(configuration);

    configuration.$inject = ['$stateProvider'];

    function configuration($stateProvider) {

        $stateProvider.state('dashboard', {
            url: '/dashboard',
            templateUrl: '/Shared/_Bodylayout',
        });
    }

})(angular);

I have a run method where the template should register all plugins exactly once for the template when rendered as :

(function () {
    'use strict';
    angular.module("ngApp").run(run);

    run.$inject = ['$rootScope', 'plugin-factory', '$timeout'];

    function run($rootScope, plugins, $timeout) {

        $rootScope.$on('$viewContentLoaded', function (event) {
             plugins.run();
        });
    }

})(angular);

But on console.log shows that this event runs for multiple times and the plugins.run() method has been called at least 5 times for a single templateURL !!! That makes my sidebar plugin behave weird .

Can anyone tell me why its running 5 times instead of one time for a single templateURL ?

enter image description here

Joy
  • 6,438
  • 8
  • 44
  • 75
  • do you have 5+ ui-view attred tags too? – YOU Apr 25 '15 at 15:41
  • @YOU nope . I have only one . The one which I have given above . But in the child BodyLayout I do have but they are all named – Joy Apr 25 '15 at 16:30
  • as far as I know, each ui-view attr trigger $viewContentLoaded event. – YOU Apr 25 '15 at 16:33
  • Ok so in the sense for all ui-view="somename" also being targetted by the state mentioned above ? – Joy Apr 25 '15 at 16:34
  • I am not sure about named ui-view, but normal ui-view and nested ui-view does, but I think its just a name. – YOU Apr 25 '15 at 16:35
  • well yes I guess thats the case . I removed all named `ui-view` from attrs and the the `$viewContentLoaded` came down to two . But still its two but not one – Joy Apr 25 '15 at 16:37
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/76243/discussion-between-joy-and-you). – Joy Apr 25 '15 at 16:42
  • I have no idea why it is two. do you have abstract? – YOU Apr 25 '15 at 16:44
  • Nope No abstract is there . Now only a Layout into which I have ui-view ... and inside the layout I am rendering bodylayout . But bodylayout doesn't have any sort of ui-view anymore – Joy Apr 25 '15 at 16:47
  • I see, strange indeed. – YOU Apr 25 '15 at 16:48
  • I have removed all occurances of ui-view except for the root ui-view which is unnamed . Still the count is two – Joy Apr 25 '15 at 16:49
  • may be you can debug, some of its event like in this post - http://stackoverflow.com/questions/20745761/what-is-the-angular-ui-router-lifecycle-for-debugging-silent-errors – YOU Apr 25 '15 at 16:53

0 Answers0