0

I want to pass some query parameters from html to the controller. It is not working like I thought it would. Here is my code. Basically, I have 3 parameters. The imei is the path variable, the startdate and enddate are the query parameters.

HTML

  <td sortable="'imei'" data-title="'IMEI'">
     <a ng-href="#/{{row.imei}}/graph?startDate={{main.startDate}}&
       endDate={{main.endDate}}">{{row.imei}}
     </a>
  </td>

RouteProvider code

function MainConfig($routeProvider) {
  $routeProvider.when('/main', {
      templateUrl: 'main/main.html',
      controller: 'MainCtrl',
      controllerAs: 'main'
    })
    .when('/:imei/graph?startDate&endDate', {
      templateUrl: 'graph/graph.html',
      controller: 'GraphCtrl',
      controllerAs: 'graph'
    });
}

Controller code

function GraphCtrl(Graph, $filter, RcTableParams, moment, $routeParams) {
  var graph = this;
  graph.imei = $routeParams.imei;
  graph.startDate = $routeParams.startDate;
  graph.endDate = $routeParams.endDate;
  . 
  .
}

I know the Path Parameter works. As soon as I added the query parameters, the code stopped working. Am I specifying the route information correctly ? Thanks for you time.

tadpole
  • 1,209
  • 7
  • 19
  • 28
  • Change to a more RESTful-ish URL. See: http://stackoverflow.com/questions/15155911/how-to-pass-querystring-in-angular-routes – stephen.vakil Sep 03 '15 at 16:39

1 Answers1

1

you can use the $location service for that

function GraphCtrl(Graph, $filter, RcTableParams, moment, $routeParams,$location) {
  var graph = this;
  graph.imei = $routeParams.imei;
  graph.startDate = $location.search().startDate;
  graph.endDate = $location.search().endDate;

  . 
  .
}
Akshay Dhankhar
  • 274
  • 1
  • 6