Javascript 角度UI路由器-在url中插入参数

Javascript 角度UI路由器-在url中插入参数,javascript,angularjs,angularjs-scope,angular-ui-router,angularjs-ng-repeat,Javascript,Angularjs,Angularjs Scope,Angular Ui Router,Angularjs Ng Repeat,在一个项目中,我需要显示url链接,并根据我在url中传递的参数/id呈现数据。在下面的链接中,AWS是id 链接: 链接: 当前,数据根据我从下拉列表中选择的id呈现,但url没有更改。我下面有一些代码,但不确定我到底做错了什么 应用程序: define app routes $stateProvider .state('table', { url: '/table', template

在一个项目中,我需要显示url链接,并根据我在url中传递的参数/id呈现数据。在下面的链接中,AWS是id

链接:

链接:

当前,数据根据我从下拉列表中选择的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>

TID ID
  • {{tid}
服务
对json进行HTTP调用时,您需要在单击项时导航到其他状态,因此最好在某个位置使用
UISREF
指令来简化此操作

<a ui-sref="table.test({tid: tid})">{{tid}}</a>
而不是

$state.location('table.test', {'ID': tid})

您需要在单击项时导航到其他状态,因此最好在某个位置使用
ui-sref
指令来简化操作

<a ui-sref="table.test({tid: tid})">{{tid}}</a>
而不是

$state.location('table.test', {'ID': tid})

我认为这个
$state.location('table.test',{'ID':tid})
应该像这个
$state.go('table.test',{tid:tid})至少这是我使用的东西我认为这个
$state.location('table.test',{ID':tid})
应该像这个
$state.go('table.test',{tid:tid})至少我用的就是这个谢谢你这个有效!但是,当我将URL复制并粘贴到新页面上时,数据不会加载。我怎样才能解决这个问题?谢谢你,这很有效!但是,当我将URL复制并粘贴到新页面上时,数据不会加载。我怎样才能解决这个问题?