我正在嘗試設定如下路線:
$stateProvider.state('transactions', {
url: '/transactions',
templateUrl: url,
menu: 'Transactions'
});
$stateProvider.state('audit', {
url: '/transactions/:id/audit',
templateUrl: 'url',
});
我希望用戶使用以下網址導航到審核頁面:
/transactions/100/audit
/transactions/200/audit
我有一個按鈕,它有一些邏輯可以將用戶重定向到“審核”頁面,但我對如何設定 $state 來實作這一點感到困惑?
$scope.redirectToAudit = function () {
$state.go('audit', {
id: $scope.transactionId
});
}
因此,當單擊此按鈕時,我想將用戶重定向到此路由“ /transactions/100/audit”并進入transactionId 100審核日志頁面的控制器。
var app = angular.module('myApp', []);
app.controller('auditCtrl', function($scope) {
$scope.transactionId = //retrive transactionId from the path parameter
});
我想在審計 URL 中強制使用事務 id,/transactions/100/audit因為整個審計頁面將只處理事務 id。
如何設定我的 $stateProvider 以支持我上面描述的 URL 和功能?
uj5u.com熱心網友回復:
請讓我知道這是否適合您。
$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;
});
}
});
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/420639.html
標籤:
下一篇:與angularjs的條帶集成
