I've a problem with UI-Router in my ionic app, I don't understand how can I go to state child defined by id using $state.go(state)
this is my stateProvider:
$stateProvider
.state('tab', {
url: "/tab",
abstract: true,
templateUrl: "templates/tabs.html"
})
.state('tab.home', {
url: '/home',
views: {
'tab-home': {
templateUrl: 'templates/tab-home.html',
controller: 'HomeCtrl'
}
}
})
.state('tab.chats', {
cache: false,
url: '/chats',
views: {
'tab-chats': {
templateUrl: 'templates/tab-chats.html',
controller: 'ChatsCtrl'
}
}
})
.state('tab.chat-detail', {
url: '/chats/:chatId',
views: {
'tab-chats': {
templateUrl: 'templates/chat-detail.html',
controller: 'ChatDetailCtrl'
}
}
})
from the homeCtrl
I would like to go in chats detail. Firstly I used $location(tab/chats/123)
but sometimes give me problems..
How can I pass the id using $state.go()
?
This is very easy to find in doc $state.go
go(to, params, options)
so, we can do it like this:
$state.go('tab.chat-detail', {chatId : 123 });
small cite from the doc about the second parameter params
A map of the parameters that will be sent to the state, will populate
$stateParams
. Any parameters that are not specified will be inherited from currently defined parameters. This allows, for example, going to a sibling state that shares parameters specified in a parent state. Parameter inheritance only works between common ancestor states, I.e. transitioning to a sibling will get you the parameters for all parents, transitioning to a child will get you all current parameters, etc.