AngularJS - $routeParams with $location -
AngularJS - $routeParams with $location -
i've been using next routing
contractmanagementapp.config(['$routeprovider', function ($routeprovider) { $routeprovider. when('/clients', { templateurl: 'partials/clientlist.html', controller: 'clientlistctrl' }). otherwise({ redirectto: '/fail' }); ]);
i'd able pass parameter page, id filter by. i've found setting next code in controller:
if ($routeparams.clientid) { //do stuff }
and pasting next browser:
[linktomyhost]/clients?clientid=107
i result desire. when trying redirect code:
var path='/clients?clientid=' + $scope.clientid; $location.path(path);
this fails , takes me 'otherwise' condition.
can this? i'm trying avoid having different route status when want pass optional filter id
try doing this:
$routeprovider. when('/clients', { templateurl: 'partials/clientlist.html', controller: 'clientlistctrl' }). when('/clients/:clientid', { templateurl: 'partials/clientlist.html', controller: 'clientlistctrl' }). otherwise({ redirectto: '/fail' });
then can pass in id so:
[linktomyhost]/clients/107
if must utilize query parameters, can this:
$location.search('clientid', 107).path('/clients');
...and can retrieve value so:
var searchobject = $location.search(), // returns {clientid:107} clientid = searchobject.clientid;
angularjs
Comments
Post a Comment