AngularJS app using ui-router. My list page loads correctly, but when clicking on links on the list page my url changes but my html on the page does not change, it remains on the list page. What is wrong with this routing?
app.js
var myApp = angular.module('myApp', ['ui.router']);
myApp.config([
'$stateProvider', function($stateProvider) {
$stateProvider
.state('products', {
url: '',
templateUrl: 'Scripts/templates/manageProducts/products.list.html',
controller: 'productListCtrl'
})
.state('products.detail', {
url: '/:id',
templateUrl: 'Scripts/templates/manageProducts/products.detail.html',
controller: 'productDetailCtrl'
});
}
]);
Index.html
<div ng-app="myApp">
<div ui-view></div>
</div>
On the products.list.html template:
<a ui-sref="products.detail({ id: 1 })">Detail for Item 1</a>
Should I even be using UI Router? The list and details page are 2 distinct screens.
There is an plunker, which should help to give an answer:
In case, that we would continue with
productDetails
state, we do loose something (if not even a lot).In the example we can see this state definition:
Until now we've seen the standard nested states parent/child. Next we will define the sub-state, while targeting the root
ui-view=""
Firstly, the inheritance in javascript/scopes is tremendously explained here:
And also, important is, that scopes in ui-router are inherited in a way of "view nesting"
A fundamental cite:
So what is all this answer about? To say: if we will use
ui-router
, the biggest benefit is the scope inheritance. Parent can do something once... child(ren) can just reuse it.Also see:
Using a root abstract state:
I had to make the details page it's own state, as follows:
instead of 'product.details' I used 'productDetails'