[英]Angular UI Router- insert param in url
在我需要显示url链接并根据我在我的URL中传递的param / id呈现数据的项目上工作。 在以下链接中,AWS是id。
链接: http : //link.com/Inventory/ListInventory/TID/AWS/JSON
链接: http : //link.com/Inventory/ListInventory/TID/param/JSON
目前,数据呈现基于我从下拉列表中选择的ID,但url不会更改。 我在下面有一些代码,但不确定我到底在做什么错。
应用程序:
define app
routes
$stateProvider
.state('table',
{
url: '/table',
templateUrl: './js/views/tableTmpl.html',
controller: 'tableCtrl'
})
.state('table.test',
{
url: '/test/:tid',
templateUrl: './js/views/tableTmpl.html',
controller: 'tableCtrl'
});
调节器
(function () {
var app = angular.module('inventory_app');
app.controller('tableCtrl', function($scope, tableService, uiGridConstants, $stateParams, $state) {
/************************************************
GLOBAL TEAM ID VALUES
************************************************/
$scope.tids = ['AWS', 'RET', 'DO', 'HELLO', 'HG', 'MIM', 'ALL'];
var globalteamId = 'AWS';
$scope.tidsIdFunc = function(tidId) {
globalteamId = tidId;
$scope.itemClick = function(tid){
$state.location('table.test', {'ID': tid})
};
/*Pass in argumnet for the functions below*/
getCost(globalteamId);
getAllData(globalteamId);
pieGraph(globalteamId);
histoGraph(globalteamId);
lineGraph(globalteamId);
};
视图
<div class="dropdown">
<button class="btn btn-primary dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
TID ID
<span class="caret"></span>
</button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
<li ng-repeat ="tid in tids">
<!-- <a ng-click="tidsIdFunc(tid)">{{tid}}</a> -->
<a ng-click="itemClick(tid)">{{tid}}</a>
</li>
</ul>
</div>
</div>
</div>
服务对json进行HTTP调用
您需要在项目单击时导航到其他状态,因此最好在某个地方使用ui-sref
指令使其更简单
<a ui-sref="table.test({tid: tid})">{{tid}}</a>
真正的问题是你正在调用$state
API的错误方法来浏览页面。
它应该是
$state.go('table.test', {'tid': tid})
代替
$state.location('table.test', {'ID': tid})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.