javascript - angularjs $resource how to call multiple services -
i've started angularjs yesterday , have reached this part of tutorial there example of using $resource accessing data services. running example in asp.net mvc , have different configuration of json files stored. json file containing list of phones , bunch of files containing detailed description of each phone in separate folders. problem see it, line:
return $resource('phones/:phoneid.json', {}, { query: {method:'get', params:{phoneid:'phones'}, isarray:true}
as per folder structure json file containing list of phones accessible using line modified 1 above
return $resource('/myangularscripts/:phoneid.json.htm', {}, { query: { method: 'get', params: { phoneid: 'jsonphonedata' }, isarray: true }
i changed extension .htm because did not want add handler iis express. file extension not problem can see list of phones. when click on each phone should able see detail description json file folder. folder is: /content/phonedata/{all various phone data json files here}
currently 404 not found because detail file in /content/phonedata/motorola-xoom-with-wi-fi.json.htm
hitting url /myangularscripts/motorola-xoom-with-wi-fi.json.htm
how modify service allow 2 different urls?
current service code:
var phonecatservices = angular.module('phonecatservices', ['ngresource']); phonecatservices.factory('phone', ['$resource', function ($resource) { return $resource('/myangularscripts/:phoneid.json.htm', {}, { query: { method: 'get', params: { phoneid: 'jsonphonedata' }, isarray: true } }); }]);
current controller code getting list of phones: $scope.phones = phone.query();
current controller code getting detail of selected phone:
$scope.phone = phone.get({ phoneid: $routeparams.phoneid }, function (phone) { $scope.mainimageurl = phone.images[0]; });
how modify controller code call services well?
yes can specify url each action
return $resource( "/myangularscripts/:phoneid.json.htm", { id: "@id" }, { 'get':{url:'/content/phonedata/'+:phoneid+'json.html}, 'query' : {url:'/myangularscripts/jsonphonedata.json.html'}, } );
Comments
Post a Comment