loadProfile();
function loadProfile() {
return loadProfileResource().then(function() {
console.log('loadProfileResource Activated!');
});
}
function loadProfileResource() {
return ProfileFactory.getProfile.query()
.then(function(data) {
$scope.profile = angular.copy(data);
return $scope.profile;
});
}
return {
getActiveProfile: getActiveProfile,
getProfile: getProfile
};
function getActiveProfile() {...}
function getProfile() {
var profile = $resource('/loadProfile&token='+$rootScope.token, {id_profile: '@id_profile'})
return profile;
/*
с исп $http все просто и понятно и это работает
return $http.get('/loadProfile&token='+$rootScope.token)
.then(getActiveProfileComplete)
.catch(getActiveProfileFailed);
*/
function getActiveProfileComplete(response) {
console.log(response);
return response.data;
}
function getActiveProfileFailed(error) {
console.log('XHR Failed for getActiveProfile.' + error.data);
}
}
$scope.profile = ProfileFactory.getProfile($rootScope.token);
function getProfile(token) {
var profile = $resource('/loadProfile', {token:token, id_profile: '@id_profile'});
return profile.query();
}
function loadProfileResource() {
return ProfileFactory.getProfile(token).test({id_profile: 158}).then(function(data) {
// или вариант
// return ProfileFactory.getProfile(token).get().then(function(data) {
// .query(), update и т.д.
$scope.profile = angular.copy(data);
console.log('+++');
return $scope.profile;
});
}
(function() {
'use strict';
angular
.module('LenaPillars')
.factory('ProfileFactory', ProfileFactory);
ProfileFactory.$injector = ['$rootScope', '$resource', '$http', 'logger'];
function ProfileFactory($rootScope, $resource, $http, logger) {
return {
getActiveProfile: getActiveProfile,
getProfile: getProfile
};
function getActiveProfile() {
return $http.get($rootScope.storeUrl+'/checkProfile&token='+$rootScope.token)
.then(getActiveProfileComplete)
.catch(getActiveProfileFailed);
function getActiveProfileComplete(response) {
console.log(response);
return response.data;
}
function getActiveProfileFailed(error) {
console.log('XHR Failed for getActiveProfile.' + error.data);
}
}
function getProfile(token) {
return $resource($rootScope.storeUrl+'/loadProfile&token='+$rootScope.token, {id_profile: '@id_profile'}, {
test: {
method: 'GET'
},
variant: {
//и список других методов
}
});
}
}
})();