0

Issue originally was trying to set the parameters in the url correctly, however, this post solved it: How can I set a query parameter in AngularJS without doing a route?

Then a new problem arose. When setting the url in the controller,

$scope.view = function(itemtmpl) {
    // change path and add parameter 'id' to the url
    $location.path('/itemtemplates/view/').search('id', itemtmpl.itemdefnid);
    // also tried with $routeProvider
    $location.url('/itemtemplates/view/' + itemtmpl.itemdefnid);
};

the item's ID is interpreted as separate arguments, not one number (the url will be used to make a REST call in a factory, so it has to be a single argument).

Chrome Console Log

enter image description here

That's the primary problem.


I thought there was a problem with my $location usage, so I went to the AngularJS docs: https://docs.angularjs.org/api/ng/service/$location

Still no luck.

$routeParams variable print out says that parameters are set accordingly.

Another idea I may need clarified is why my page's config will only recognize the $location.url when it's just appended to the end view/1000, not if it's a parameter view/?1000 and still won't proceed if it has an id view/?id=1000

.config(function($routeProvider) {
  $routeProvider.when('/itemtemplates/view/:id', {
    templateUrl: 'itemtemplates/add/main.tpl.html',
    controller: 'ViewCtrl'
  });
})

What could I be missing? Thanks in advance.

Community
  • 1
  • 1
Jared
  • 109
  • 2
  • 8

1 Answers1

0

In the controller for the URL I am trying to go to, the factory call was incorrect. I have to specify what argument I am trying to fulfill in the REST call, otherwise, the parameters are interpreted loosely. In my case, as a char array.

Was...

$scope.itemtmpl = item.query($routeParams.id);

Should have been...

$scope.itemtmpl = item.query({id: $routeParams.id});

This solves the first half of the problem. I am still trying to figure out how to use the url when parameters are set using .search().

Jared
  • 109
  • 2
  • 8