Reputation: 125
I want to update same view depending on button clicked how to use stateParam and get id in controller.My app.js is as follows
angular.module('starter', ['ionic','ui.router'])
.config(function($stateProvider,$urlRouterProvider,$stateParams){
$urlRouterProvider.otherwise('/page1');
$stateProvider.state('page1', {
url: "/page1",
templateUrl: 'templates/page1.html',
controller:'dataCtrl'
})
.state('page2', {
url: "/page2",
templateUrl: 'templates/page2.html',
controller:'transCtrl'
})
})
my contoller is
angular.module('starter').controller('dataCtrl',function($scope,$state,$stateParams)
{
alert("gfb")
$scope.Jan= function (id) {
alert("inside Jan");
$state.go('page2',{id:id});
}
});
Upvotes: 0
Views: 288
Reputation: 18919
Add the param in state like so:
.state('page2', {
url: "/page2/:id",
templateUrl: 'templates/page2.html',
controller:'transCtrl'
})
In transCtrl:
angular.module('starter').controller('transCtrl',function($scope,$state,$stateParams) {
var id = $stateParams.id;
}
Upvotes: 2