1

Working on a project where I am required to show url link and render data based on the param/id I pass in my url. In the following link AWS is the id.

link: http://link.com/Inventory/ListInventory/TID/AWS/JSON

link: http://link.com/Inventory/ListInventory/TID/param/JSON

enter image description here

Currently the data renders based on the id I select from the drop down but the url doesn't change. I have some code below but not sure what exactly I am doing wrong.

App:

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);
    };

View

<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>

Service Making HTTP call to json

1
  • 1
    I think that this $state.location('table.test', {'ID': tid}) should look like this $state.go('table.test', {tid: tid}); at least that's what i'm using Commented Mar 17, 2016 at 19:48

1 Answer 1

0

You need to navigate to other state on item click, so better have it simple by using ui-sref directive in a place

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

Real problem was you are calling wrong method of $state API to navigate through page.

It should be

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

instead of

$state.location('table.test', {'ID': tid})
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you this works! But when I copy and paste the URL on a new page, the data doesn't load. How can I fix that?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.