matiasvillanueva matiasvillanueva - 8 days ago 5
AngularJS Question

AngularJS - Url format

I'm having trouble with AngularJs's url

I need something like this:

/api/menu/3


But Im getting this:

/api/menu?menuId=3


I need this 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 the problem is in services.js, but I can't find a way to do it.

Answer

Replace:

$resource( API_URL + '/api/menu', { menuId : '@menuId'}, { ...

with:

$resource( API_URL + '/api/menu/:menuId', { menuId : '@menuId'}, { ...

To avoid error:

Error: V is not a function this.$get

Update last version of angularjs