Seeking assistance for a service issue.
I have a service that can be accessed via the domain/service/webapi/
URL. When calling
domain/service/webapi/menu/getmenucategory
, it returns the JSON string representing the application's menu structure:
The problem arises when I make this call using Restangular, as I receive an empty object in return. Despite Fiddler confirming that Restangular is making the call to the web API and receiving the JSON response, I am puzzled why it does not return the expected Javascript objects.
I have reviewed the documentation but couldn't find a solution. It seems like I might have overlooked something simple.
Below are the snippets of code:
Controller:
'use strict';
dilibApp.controller('NavigationMenuController', function ($scope, navigationMenuService) {
$scope.menuCategories = navigationMenuService.GetMenuCategories();
});
Service:
'use strict';
dilibApp.factory('navigationMenuService', function(Restangular) {
return {
GetMenuCategories: function() {
//var menuCategories = Restangular.all('menu', 'getmenucategory');
var menuCategories = Restangular.all('menu/getmenucategory');
console.log(JSON.stringify(menuCategories.getList()));
return menuCategories.getList();
}
}
});
Result in Chrome Console:
{"restangularCollection":true,"$object":[]}
JSON string:
[{"$id":"1",
"Id":1,
"Name":"File",
"SortNo":0,
"IsEnabled":1,
"MenuItems":[{"$id":"2",
"Id":1,
"Name":"File menu item 1",
"IsEnabled":1},
{"$id":"3",
"Id":2,
"Name":"File menu item 2",
"IsEnabled":1}]},
{"$id":"4",
"Id":2,
"Name":"Administration",
"SortNo":1,
"IsEnabled":1,
"MenuItems":[{"$id":"5",
"Id":4,
"Name":"Administration menu item 1",
"IsEnabled":1},
{"$id":"6",
"Id":5,
"Name":"Administration menu item 2",
"IsEnabled":1}]},
{"$id":"7",
"Id":3,
"Name":"Modules",
"SortNo":2,
"IsEnabled":1,
"MenuItems":[{"$id":"8",
"Id":6,
"Name":"Modules menu item 1",
"IsEnabled":1},
{"$id":"9",
"Id":7,
"Name":"Modules menu item 2",
"IsEnabled":1}]}]