How inject $stateProvider in angular application?

前端 未结 2 1768
轮回少年
轮回少年 2021-01-01 22:50

I try to use angular-ui, and try to inject $stateProvider:

html




    

        
相关标签:
2条回答
  • 2021-01-01 23:12
    var bootstrapApp = angular.module('bootstrapDemoApp', ['ui.bootstrap','ui.router']);
    
    bootstrapApp.config(function($stateProvider, $urlRouterProvider,$locationProvider) {
    
    
    
    
     // For any unmatched url, redirect to /
     $urlRouterProvider.otherwise("/");
    
     // Now set up the states
     $stateProvider
      .state('login', {
       url: "/",
       controller: "loginCtrl",
       templateUrl: "partials/login.html"
     })
    });
    
    0 讨论(0)
  • 2021-01-01 23:20

    When using it in a controller you have to use $state:

    angular.module("appModule", ['ui.router']).controller('appController', ['$scope', '$state', function ($scope, $state) {
        $scope.date = new Date();
    }]);
    

    You can only use the state provider in the config, for example:

    angular.module('appModule').config(['$stateProvider', function($stateProvider){
        /* do w/e with state provider */
    })];
    
    0 讨论(0)
提交回复
热议问题