StateProvider angular not working and no error

流过昼夜 提交于 2020-01-15 09:25:07

问题


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

回答1:


I was using ng-view instead of ui-view




回答2:


Did you Try this

$urlRouterProvider.otherwise("/");

Instead of

$urlRouterProvider.when('', '/');



回答3:


It should be controller: "HomeCtrl"

instead of

controller: "HomeCtrl as ctrl"

Controller key would only take the name of the controller.



来源:https://stackoverflow.com/questions/37199566/stateprovider-angular-not-working-and-no-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!