问题
I am trying to use $stateProvider
for my url routing. I thought that if I use $stateProvider
, then I don't need to use $routeProvider
. Is this correct? I was able to get my url routing to work with $routeProvider
, but am unable to get my url routing to work with $stateProvider
. Here is the code I have so far:
var app = angular.module("app",['ui.state']);
app.config(function($urlRouterProvider, $stateProvider, $locationProvider) {
$urlRouterProvider.otherwise("/home")
$stateProvider
.state('home', {
url: "/home",
controller: 'HomeCtrl',
views: {
main: { templateUrl: "views/home/main.html" }
sub: { templateUrl: "views/home/sub.html" }
}
})
.state('products/info', {
url: "/products/info",
controller: 'ProductsCtrl',
views: {
main: { templateUrl: "views/products/main.html" },
sub: { templateUrl: "views/products/info/sub.html" }
}
})
.state('products/reviews', {
url: "/products/reviews",
controller: 'ProductsCtrl',
views: {
sub: { templateUrl: "views/products/reviews/sub.html" }
}
})
On my "shell" html page I have the following:
<div class="main">
<div ui-view="main"></div>
<div ui-view="sub"></div>
</div>
When I visit any of my urls I only see the shell html page. Nothing is being loaded into my ui-view
's. What am I missing?
回答1:
here,your state type 'products/reviews' is wrong,it should be 'products.reviews'
回答2:
This page explained it: AngularJS State Management with ui-router
回答3:
The dependency name is 'ui.router' not 'ui.state'
来源:https://stackoverflow.com/questions/17661415/stateprovider-not-loading-pages-as-expected