angularjs - angular $routeProvider resolve -


i want create menu dynamically, that, use resolve before loading dashboard.

var app = angular.module('mabnaaapp', ['ngroute', 'ngresource', 'nganimate', 'ui.bootstrap', 'ur.file']) .config(function ($routeprovider) {     $routeprovider         .when('/login', {             templateurl: 'views/login.html',             controller: 'loginctrl'         })         .when('/dashboard', {             templateurl: 'views/dashboard.html',             resolve: {                 menu: function (menuservice) {                     return menuservice.getmenu();                 }             },             controller: function ($scope, menu) {                 $scope.menu = menu;                 $scope.oneatatime = true;             }         })         .when('/flatfile', {             templateurl: 'views/flatfile.html'         })         .when('/view/:vtid/:prid', {             templateurl: 'views/viewdetail.html',             controller: 'viewdetailcontroller'         })         .otherwise({             redirectto: '/login'         }); }).factory('menuservice', function ($q, $http) {     var getmenu = function () {         var deferred = $q.defer();         $http.post('/m1object/menu', 1).             success(function (data) {                 deferred.resolve(data);             }).             error(function (data, status, header, config) {                 $log.warn(data, status, header(), config);                 deferred.reject(status);             });         return deferred.promise;     };      return{         getmenu: getmenu     } }); 

my menu load , after create menu in dashboard.

    <accordion close-others="oneatatime"><!--nashta-->     <accordion-group heading="{{project.name}}" ng-repeat="project in menu.projectname">          <accordion close-others="oneatatime"><!--bank-->             <accordion-group heading="{{bank.name}}" ng-repeat="bank in menu.bankinglist" is-disabled="bank.value == null? true:false">                  <accordion close-others="oneatatime"><!--working pack-->                     <accordion-group heading="{{wp.name}}" ng-repeat="wp in menu.workingpacklist" is-disabled="wp.value == null? true:false">                          <accordion close-others="oneatatime"><!--product pack-->                             <accordion-group heading="{{pr.name}}" ng-repeat="pr in menu.productlist" is-disabled="pr.value == null? true:false">                                  <accordion ng-repeat="vt in menu.viewtype">                                     <li ng-controller="viewdetailcontroller"><a href="/app/index.html#/view/{{pr.value}}/{{vt.value}}" ancher-cheking ng-click="getviewdetail">{{vt.name}}</a></li>                                 </accordion>                              </accordion-group>                         </accordion>                      </accordion-group>                 </accordion>              </accordion-group>         </accordion>     </accordion-group> </accordion> 

now user can select 1 of viewtype see detail in viewdetail.html. want call getviewdetail viewdetailcontroller controller handel it.

                                    <accordion ng-repeat="vt in menu.viewtype">                                     <li ng-controller="viewdetailcontroller"><a href="/app/index.html#/view/{{pr.value}}/{{vt.value}}" ancher-cheking ng-click="getviewdetail">{{vt.name}}</a></li>                                 </accordion> 

but don`t know happen when menu creating,the getviewdetail function of viewdetailcontroller controller called!!! point getviewdetail viewdetailcontroller called before menu create , without clicking on menu.

enter image description here

viewdetailcontroller:

    .controller('viewdetailcontroller', function ($scope, $modal, $routeparams, $log, viewdetailservice) {      var getviewdetail = function () {         var list = viewdetailservice.getviewdetail($routeparams.prid, $routeparams.vtid);         list.then(             function (result) {                 $scope.list = result;              }, function (status) {             });     }; 

what problem?why getviewdetail function called during creation of menu?


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -