GunService.posts({}).$promise.then(function (data) {
$scope.guns = data.results;
});
$scope.addNewGun = function () {
GunService.publish({
gun_type: "fireball",
data: {
text: $scope.post.text
}
}).$promise.then(function () {
//как правильно тут вызвать (reload) GunService.posts? Нужно ее завернуть в функцию ранее?
})
};
function GunService ($rootScope){
this.onGunAdded = function (callback){
return $rootScope.$on(GunService.events.ADDED, callback);
};
this.publish = function (params){
// do your thing ...
.then(function (newGun){
$rootScope.$emit(GunService.events.ADDED, newGun);
});
}
}
GunService.events = {
ADDED: 'GunService.added'
};
function SomeController(GunService) {
GunService.onGunAdded(gunAdded);
this.add = function (){
// do your thing
}
function gunAdded(newGun) {
// Use newly created gun or do .posts
}
}