angular $ routeProvider解析

时间:2015-04-23 07:43:07

标签: angularjs

我想动态创建我的菜单,为此,我在加载仪表板之前使用resolve。

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
    }
});

我的菜单加载完美,之后我在仪表板中创建了菜单。

    <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>

现在用户可以选择一个viewType来查看viewDetail.html中的详细信息。我想从ViewDetailController控制器调用getViewDetail来handel它。

                                    <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>

但我不知道菜单创建时会发生什么,调用ViewDetailController控制器的getViewDetail函数! 我的观点是来自ViewDetailController的getViewDetail在我的菜单完全创建之前被调用,而没有点击任何菜单。

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) {
            });
    };

我的问题是什么?为什么在创建菜单期间调用getViewDetail函数?

0 个答案:

没有答案