I am trying to creating web page to perform on edit actions in both in parent(first.edit) and child(second.edit) states. I sending related state parameters through URL, those are captured by using regex patterns.
When I click on ui-sref="home.first.edit({firstId:10})" link the controller receiving state parameter firstId correctly i.e 10.
When I click on ui-sref="home.first.second.edit({firstId:10,secondId:20})" link or refresh the the state the controller receiving in correct value for firstId i.e 10/second/20. and it is moving to parent state(home.first)
This is my js file
angular.module('MyApp', [
'ui.router'
])
.config(function($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise('/home');
Here are the states:
$stateProvider.state('home', {
url: '',
views: {
'home_view': {
templateUrl: 'index.html',
controller: 'homeController'
}
}
})
.state('home.first', {
url: "/first",
params:{
firstId:null
},
views: {
'home_view': {
templateUrl: "first.html",
controller: 'firstCtrl'
}
}
})
.state('home.first.edit', {
url: "/{firstId:[0-9]+}/edit",
views: {
'first_view': {
templateUrl: "/edit_first.html",
controller: 'firstCtrl'
}
}
})
.state('home.first.second', {
url: "/second",
params:{
secondId:null
}
views: {
'first_view': {
templateUrl: "/second.html",
controller: 'secondCtrl'
}
}
})
.state('home.first.second.edit', {
url: "/{secondId:[0-9]+}/edit",
views: {
'second_view': {
templateUrl: "/views/testplan/projects/edit_second.html",
controller: 'secondCtrl'
}
}
})
Here is the rest of the code with controller definition
.controller(
'homeController',
function($scope, $state, $stateParams) {
// console.log($stateParams.firstId);
}
)
.controller(
'firstCtrl',
function($scope, $state, $stateParams) {
console.log($stateParams.firstId);
}
)
.controller(
'secondCtrl',
function($scope, $state, $stateParams) {
console.log($stateParams.secondId);
}
);