Issue
I am trying to set up route like below :
$stateProvider.state('transactions', {
url: '/transactions',
templateUrl: url,
menu: 'Transactions'
});
$stateProvider.state('audit', {
url: '/transactions/:id/audit',
templateUrl: 'url',
});
I want user to navigate to audit page using below url:
/transactions/100/audit
/transactions/200/audit
I have a button which has some logic to redirect user to "audit" page but I am confused with how do I set up $state to achieve this?
$scope.redirectToAudit = function () {
$state.go('audit', {
id: $scope.transactionId
});
}
So when this button is clicked I want to redirect user to this route "/transactions/100/audit
" and get transactionId 100
in the controller of audit log page.
var app = angular.module('myApp', []);
app.controller('auditCtrl', function($scope) {
$scope.transactionId = //retrive transactionId from the path parameter
});
I want to force transaction id in audit URL /transactions/100/audit
because entire audit page will be working on transaction id only.
How do I set up my $stateProvider to support the URL and functionality I have described above?
Solution
Please let me know if this works for you.
$stateProvider.state('transactions', {
url: '/transactions',
templateUrl: url,
menu: 'Transactions'
});
$stateProvider.state('audit', {
url: '/transactions/{id}/audit',
templateUrl: 'url',
});
----------------------
var app = angular.module('myApp', []);
app.controller('auditCtrl', function($scope, $stateParams) {
$scope.transactionId = $stateParams.id;
});
----------------------
app.controller('transactionsCtrl', function($scope, $state) {
$scope.redirectToAudit = function () {
$state.go('audit', {
id: $scope.transactionId;
});
}
});
Answered By - Gerald LeRoy
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.