I'm new to Angular and I've been struggling for a while trying to call a factory that uses Restangular in one of my controllers. Here is the controller:
'use strict';
angular.module('myApp')
.controller('UserCtrl', ['WebApi', function($scope, WebApi) {
$scope.user = WebApi.getProfile(1);
}
]);
Whenever I call the WebApi factory in my controller, the WebApi object is empty. When I call the method, it will then return undefined. When I log the object in the console, I get
Object {}
Here is my factory:
"use strict";
angular.module("myApp.services", ["restangular"])
.factory("WebApi", ["Restangular", function(Restangular) {
var getProfile;
Restangular.withConfig(function(RestangularConfigurer) {
RestangularConfigurer.setBaseUrl("http://127.0.0.1:3000/api/v1");
});
getProfile = function(id) {
Restangular.one("users", id).get().then(function(data) {
return data;
});
};
}
]);
App module:
'use strict';
angular.module('myApp', ['ngCookies', 'ngSanitize', 'ui.router', 'myApp.services']);
And it's included in my index html:
<script src="scripts/app.js"></script>
<script src="scripts/controllers/main.js"></script>
<script src="scripts/services/webapi.js"></script>
<script src="scripts/controllers/user.js"></script>
What am I doing wrong? Thank you in advance.