AngularJS - Dynamic $StateProvider

前端 未结 2 1707
醉梦人生
醉梦人生 2021-02-06 19:05

I am eagerly trying to create a dyanmic $StateProvider:

Standard static $StateProvider:

    $stateProvider
      .state(\'main\         


        
2条回答
  •  北荒
    北荒 (楼主)
    2021-02-06 19:52

    Solution:

    var states = [
    { name: 'main', url: '/', templateUrl: '/views/main.html', controller: 'MainCtrl' },
    { name: 'login', url: '', templateUrl: '/views/login-form.html', controller: 'LoginCtrl' },
    { name: 'logout', url: '', templateUrl: '', controller: 'LogoutCtrl' },
        {
            name: 'sales',
            url: '',
            templateUrl: '/views/sales-data.html',
            controller: 'SalesDataCtrl',
            resolve: {
                user: 'User',
                authenticationRequired:
                ['user', function(user) { user.isAuthenticated(); }] // <-------------------------
            }
        }
    ];
    
        angular.forEach(states, function (state) {
            $stateProvider.state(state.name, state);
        });
    

提交回复
热议问题