rest - AngularJS use $location within a factory -


i created factory using $resource factory, want customise url params passed $resource according current url. here's code sample:

myapp.factory("provider_services", ['$resource', function($resource) {   var factory = {};   var providerservice = $resource("/providers/:provider/provider_services/", { format: 'json', provider: "pro" });   factory.services = providerservice.query();    return factory; }]) 

my current url is: somedomain.com/providers/pro/services/

i want pull "pro" part out of url (that ideally can else) , pass in provider param resource (in current sample can see it's hardcoded). like:

cur_provider = {get current value url} var providerservice = $resource("/providers/:provider/provider_services/", { format: 'json', provider: cur_provider }); 

*i know can using $location somehow, can't seem access within provider_services factory.

thanks !

you can use $routeparams this. this:

angular.module('app').controller("examplecontroller", ['$resource', '$routeparams', 'someservice',     function($resource, $routeparams, someservice) {         //the id here whatever name route variable.         cur_provider = $routeparams.provider;         var providerservice = $resource("/providers/:provider/provider_services/", { format: 'json', provider: cur_provider });     } ]); 

Comments

Popular posts from this blog

searchKeyword not working in AngularJS filter -

sequelize.js - Sequelize: sort by enum cases -

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -