javascript - AngularJS - Url format -
i'm having trouble angularjs's url
i need this:
/api/menu/3
but im getting this:
/api/menu?menuid=3
i need format beacuse i'm using laravel.
app.js:
var app = angular.module('mainmodule', ["ngroute", "ngresource", 'mainmodule.services', 'mainmodule.controllers']) .config(function($routeprovider, $locationprovider) { $routeprovider .when("/", { templateurl : "templates/dashboard.html", controller : "contentcontroller" }) .when("/:id", { templateurl : "templates/dashboard.html", controller : "contentcontroller" }) .when("/config/:id", { templateurl : "templates/config.html", controller : "configmenucontroller" }) .when("/account", { templateurl : "templates/account.html" }) .otherwise({ templateurl : "templates/error.html" }) //$locationprovider.html5mode(true); } );`
controller.js
angular.module('mainmodule.controllers',[]); angular.module('mainmodule.controllers') .controller('configmenucontroller', function($scope, $http, $routeparams, api_url, submenu) { var id=$routeparams.id $scope.submenu = submenu.query({ menuid : id }, function() { console.log($scope.submenu); }); });
services.js
var api_url = 'http://test.com' angular.module('mainmodule.services', []) .constant('api_url', 'http://test.com') .factory('submenu', function($resource) { return $resource( api_url + '/api/menu', { menuid : '@menuid'}, { update: { method: 'put' } }); });
i think problem in services.js, can't find way it.
replace:
$resource( api_url + '/api/menu', { menuid : '@menuid'}, { ...
with:
$resource( api_url + '/api/menu/:menuid', { menuid : '@menuid'}, { ...
yes, add /:menuid
url. $resource
replaces :attr
value attr
property object. if :attr
not found, it's added url query param. that's happening.
Comments
Post a Comment