Note that there are some explanatory texts on larger screens.

plurals
  1. POAngularJS - Changing a query param term within $routeProvider?
    primarykey
    data
    text
    <p>I am creating a navigation, where when on the active 'link', a feed loads but with a different searched term. </p> <p>Basically, the all the links are the same, the only difference is the term set in the .factory parameter.</p> <p>Since everything is the same (even the .controller, is it possible to set the query term inside of the routeProvider, where I can specify the term that needs to be searched?</p> <p>Or will the only way is to create a new controller for each link, and set the term inside of there? Keeping the code simple, efficient and as little as possible, is what I am trying to aim for.</p> <pre><code> angular.module('termSearch', ['ngResource']) .config(['$httpProvider', function ($httpProvider) { $httpProvider.defaults.headers.common["X-Requested-With"] = undefined; }]) .config(function($routeProvider) { $routeProvider .when('/term1', {templateUrl: 'views/feedlist.html', controller: 'searchtermCtrl' }) .when('/term2', {templateUrl: 'views/feedlist.html', controller: 'searchtermCtrl' }) .otherwise({redirectTo: '/term1'}); }) .factory('Feed', function ($resource) { return $resource('https://www,example.com/:term/json', {}, { query: { method: 'GET', isArray: false, params: { term: "term#" } } }); }) .controller('searchtermCtrl', function($scope, Feed){ $scope.results = Feed.query(); $scope.feed = function (term) { Feed.get({ term: term }, function (results) { $scope.results = results console.log(results); }); } }) </code></pre> <p>Thanks for any help in the right direction.</p> <p>Roc.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload