StateProvider angular not working and no error

2019-07-27 08:12发布

I am trying to use angular-ui-route, but, with no errors in console, the stateProvider doesn't work. I am not able to see my homepage (or any other)..

What am I missing?

my app.js:

 var app = angular.module('app', ['ui.router', 'pascalprecht.translate'])
  .config(['$stateProvider', '$locationProvider', '$translateProvider', '$interpolateProvider', '$urlRouterProvider',
   function($stateProvider, $locationProvider, $translateProvider, $interpolateProvider, $urlRouterProvider) {
     $locationProvider.html5Mode(true);
     $locationProvider.hashPrefix("!");

     $interpolateProvider.startSymbol('{[{');
     $interpolateProvider.endSymbol('}]}');

     $translateProvider.useStaticFilesLoader({
       prefix: '/static/languages/',
       suffix: '.json'
     })
     .preferredLanguage('pt-br');
     $translateProvider.forceAsyncReload(true);
     $urlRouterProvider.when('', '/');
      $stateProvider.state('home', {
        url: '/',
        controller: "HomeCtrl as ctrl",
        templateUrl:"/static/includes/home.html"
      }).state('home.login', {
        url: '/login',
        templateUrl:"/static/includes/login.html"
      });
    }]);

3条回答
何必那么认真
2楼-- · 2019-07-27 08:19

Did you Try this

$urlRouterProvider.otherwise("/");

Instead of

$urlRouterProvider.when('', '/');
查看更多
孤傲高冷的网名
3楼-- · 2019-07-27 08:25

I was using ng-view instead of ui-view

查看更多
倾城 Initia
4楼-- · 2019-07-27 08:28

It should be controller: "HomeCtrl"

instead of

controller: "HomeCtrl as ctrl"

Controller key would only take the name of the controller.

查看更多
登录 后发表回答