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.

1

1 Answer 1

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;

  . 
  .
}
Sign up to request clarification or add additional context in comments.

3 Comments

The location service did not make any differences.
and please make it when .when('/:imei/graph?startDate&endDate', { to .when(/:imei/graph',{ and use same $routeParams..or you can also use $location.search() if you use proper search..
Thank you. Getting rid of the ?startDate&endDate seems to do the trick.

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.