Hi I have two separate templates named "home.html" & "home.singleLink.html" in templates folder.
home.html looks like this
<ion-list>
<ion-item ng-repeat="link in links">
<a class="button button-clear" ui-sref="home({singleLink: link.name})">{{link.name}}</a>
</ion-item>
<ion-list>
And I want to show "home.singleLink.html" template and vanishes the "home.html" template when a user click on the link what is in ui-sref. I am passing a variable after the "home"
Here is my app.config looks like
$stateProvider
.state('home', {
url: '/home',
templateUrl: 'templates/home.html',
controller: 'linksController'
})
.state('home.singleLink', {
url: '/:singleLink',
templateUrl: 'templates/home.singleLink.html',
controller: 'linksController'
})
As per I know ui-sref will generate a href when a user click in the link. But in my case when I inspect the link I can see a additional href="#/home" along with the ui-sref which is not changing when I click in the link.
Thanks in advance.
Since your templates are named home.html and home.singleLink.html I am assuming singleLink is a child of home. Your config should look like this.
And your home.html shoul look like this
We have to change to things. I created working plunker here.
Firstly, the state call:
As we can see, the ui-sref is now different
Secondly the child state view target
Because our list view (state 'home'), does not have target for child
home.singleLink
, we have to use absolute naming and place it into root:Find more here:
View Names - Relative vs. Absolute Names
Check it here, Similar stuff here: Resolving promise with ionic/ui-routing