正在开发一个项目,我需要显示 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'
});
Controller
(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})
关于javascript - Angular UI Router-在 url 中插入参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36070121/