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