681
votes
8answers
154k views

Angular.js: service vs provider vs factory?

I'm sure this has bothered you - it has bothered me for some time now. What are the differences between AngularJS module's Service, Provider and Factory?
67
votes
6answers
16k views

angular js - configuration for different enviroments

how do you manage configuration variables/constant for different enviroments? This could be an example: my rest api it's reachable on localhost:7080/myapi/, but my friend that works on the same ...
13
votes
3answers
1k views

Should services expose their asynchronicity?

I'm writing a service that will retrieve data asynchronously ($http or $resource). I can hide the fact that it is asynchronous by returning an array that will initially be empty, but that will ...
6
votes
1answer
455 views

Angular Service Definition: service or factory

I am an angular newbie, I am building an application, one thing really puzzling me is there are couple of ways of defining a service, and I read more from this link: How to define service then it ...
45
votes
3answers
16k views

AngularJS - The correct way of binding to a service properties

I’m looking for the best practice of how to bind to a service property in AngularJS. I have worked through multiple examples to understand how to bind to properties in a service that is created using ...
6
votes
2answers
4k views

Force AngularJS service to return data before loading controller

I have a service in Angular which uses my API to get user information and provides it to my controllers. It's set up like this: angular.module('myApp', ['myApp.filters', 'myApp.services', ...
4
votes
3answers
8k views

Simple Angular $routeProvider resolve test. What is wrong with this code?

I have created a simple Angular JS $routeProvider resolve test application. It gives the following error: Error: Unknown provider: dataProvider <- data I would appreciate it if someone could ...
3
votes
1answer
7k views

AngularJS Service Passing Data Between Controllers

When using an AngularJS service to try and pass data between two controllers, my second controller always receives undefined when trying to access data from the service. I am guessing this is because ...
44
votes
2answers
13k views

AngularJS: when to use service instead of factory

Please bear with me here. I know there are other answers such as: Angular.js: service vs provider vs factory? However I still can't figure out when you'd use service over factory. From what I ...
4
votes
2answers
8k views

Uploading a file with AngularJS and bluimp on success callback of another form

I have followed the following tutorial in order to integrate the notorious bluimp jQuery file uploader in my AngularJS project. After some research I found that in the options array, witihn the ...
3
votes
1answer
336 views

Firebase data normalized. How should I fetch a collection based on this structure?

I think I am getting close, I am able to print out the ID of books belonging to a user but have been trying unsuccessfully to fetch the list of books belonging to a user, from the firebase books ...
6
votes
1answer
4k views

AngularJS Directive not able to access isolate scope objects

I am trying to put some default values in my directive with Isolate scope. Basically, I need to do some DOM manipulations using the scope object when my directive is bound. Below is my code: ...
5
votes
3answers
6k views

AngularJS factory http returns empty

I'm trying AngularJS for the first time. I'm getting JSON data from a http-get request using a factory, but the object is returned empty, before the ajax-request is done. Factory: ...
1
vote
2answers
3k views

AngularJS: open a new browser window, yet still retain scope and controller, and services

I'm writing an angularJS app. In this particular controller, I open a new browser window through the $window.open service. But in the new window, all the $scope variables are lost. I tried to use ...
3
votes
1answer
383 views

Dirty checking with shared service between controllers, One way works the other does not?

While attempting to answer a question regarding sharing data between two separate controllers I ran into a question . I usually use services for for this task and began to create a jsfiddle, but I ...
0
votes
2answers
65 views

How to create this global constant to be shared among controllers in Angularjs?

Suppose I want to make this a variable a constant to be shared among controllers in Angularjs; $webroot = "localhost/webroot/app" After some investigation, it seems services are the way to do. But ...
55
votes
4answers
8k views

How can I test an an AngularJS service from the console?

I have a service like: angular.module('app').factory('ExampleService', function(){ this.f1 = function(world){ return 'Hello '+world; } return this; }) I would like to test it from the ...
31
votes
4answers
37k views

How to access the services from RESTful API in my angularjs page

I am very new to angularJS. I am searching for accessing services from RESTful API but I didn't get any idea. please help me to do that.
6
votes
2answers
6k views

How to wait till the response comes from the $http request, in angularjs?

I am using some data which is from a RESTful service in multiple pages. So I am using angular factories for that. So, I required to get the data once from the server, and everytime I am getting the ...
6
votes
1answer
457 views

The better approach to design AngularJS services

I'm writing an AngularJS client application that would interact with a REST server. To manage the client / server interaction I'm using the $resource abstraction. Actually I'm writing every resource ...
7
votes
2answers
2k views

AngularJS, is this way of using service good?

i've this HTML: <p>Hello {{name}}</p> and the controller is: function myCtrl(scope, service) { scope.name = service.getUsername(); // service.getUsername() return "World!" } ...
1
vote
2answers
2k views

Sharing data between AngularJS services

Is there a way to share data between services in AngularJS? Use case: data aggregation from different services For example I want a service1 that loads some data from a REST Service. Then another ...
10
votes
3answers
1k views

How can I extend $q promise in Angularjs with a .succes and .error

I wrote this little code in a custom service in AngularJS. In my service : var deferred = $q.defer(); var promise = deferred.promise; deferred.resolve('success'); ...
6
votes
2answers
2k views

Cordova + Angularjs + Device Ready

I am developing a mobile application using Cordova and AngularJS. How do I restrict bootstrapping of AngluarJS before Cordova device ready. Basically I don't want to use any of AngularJS controllers ...
4
votes
1answer
8k views

How to enable cors request with angular.js-resource

I have an angular.js application and i need to do CORS request. I want to define my rest services "the angular" using angular resources, described here: http://docs.angularjs.org/tutorial/step_11. ...
0
votes
2answers
1k views

AngularJS service retry when promise is rejected

I'm getting data from an async service inside my controller like this: myApp.controller('myController', ['$scope', 'AsyncService', function($scope, AsyncService) { $scope.getData = ...
6
votes
1answer
3k views

AngularJS factory property isn't being updated in $scope when not using push()

I have a factory that is retrieving the data from an external source. As soon as i get the data, i use a second factory to filter it by a certain criteria. The factory property is assigned to scope. ...
2
votes
2answers
48 views

Is there a loosly coupled way to update a parent directive from a dynamically created view/controller that is a child of the parent

In my app I have window instances. The app can contain multiple windows and windows can contain multiple views. The views are children of each window instance. The windows and view creator are ...
1
vote
1answer
601 views

AngularJS $location.path(path) not updating at first

I have a piece of code where I call $location.path(name) and nothing seems to happens (at first). I can call console.log($location.path()) and it does show the new path -- but the view doesn't change. ...
1
vote
2answers
2k views

AngularJS. Best practice concerning proper two way data binding from a service

I have an 'Account' service which acts as a centralized data storage used in multiple controllers and views. This service will hold, besides getter and setter methods all data associated with two ...
0
votes
0answers
273 views

excel file not getting after returning from Angularjs Service

I have situation where i have to call angularjs service method to post data to C# controller which in turns return me excel file which i want to save. here is code.... HTML : <div ...
0
votes
2answers
145 views

Angular how to deal with unavailable URLs requested by $http.get or $http.jsonp, which are executed by $q.all()

I've the following code: eventResourcesCall = $http.jsonp('https://apicall/to/serverA'); eventsDetailsCall = $http.get('https://apicall/to/serverB'); $q.all([eventResourcesCall, ...
0
votes
1answer
2k views

AngularJS share asynchronous service data between controllers

I know this issue has been asked several times in stackoverflow, but I couldn't find a proper answer. What I need to achieve is to be able to initiate some asynchronous call in one controller and ...
3
votes
1answer
154 views

Abstracting $http calls into service

I'm wondering what the best way to abstract $http calls into an angularjs service is. I've done a bit of research and this seems to be the most common way: app.factory('myService', function($http) { ...
1
vote
1answer
265 views

Restangular api calls to external getting 'No Access Allowed'

Following Restangular's documentation and includes an example of this: // GET to http://www.google.com/ You set the URL in this case Restangular.allUrl('googlers', ...
1
vote
3answers
32 views

How to create a object with properties that are sharable among controllers in AngularJS?

This is a follow-up question to How to create this global constant to be shared among controllers in Angularjs? The answer provided allows a constant $webroot to be shared among controllers. app = ...
1
vote
1answer
284 views

Resolve login in $routeProvider using controller

I'm trying to restrict a user's access to a /topics view and a /question view. I have a login form on the home page. My HomeCtrl has the following login function: $scope.doLogin = function() { ...
1
vote
0answers
451 views

Using Angularjs $http in browser console

I've testing AngularJS services in browser console during development for quick verification. The way I inject a service into console is as describe in this question or var $inj = ...
1
vote
2answers
2k views

AngularJS directive and pulling data from a service

I am trying to figure out the correct way to pull data into my directive from a service. For some reason my $watch statement isn't triggered when the data is loaded. link: function(scope, element, ...
1
vote
1answer
332 views

AngularJS - AlertFactory open dialog behavior

i'm creating an AlertFactory because ui.bootstrap.dialog doesn't works in my app. So i type follow code: http://jsfiddle.net/Premier/BHqKB/17/ enter code here It works very well if you click on ...
0
votes
1answer
156 views

Angular controller can't get data from service

Background: I'm learning AngularJS, I've written sample code to create a service for a module, and pass the data from service into one of the module's controller, all works fine. But yesterday when I ...
0
votes
1answer
251 views

angularJS $stateParams in service

I try to fetch JSON data on the page post/:postId within the following factory in my service: angular.module('sampleapp.services', []) .factory('DetailService', function($http) { return { ...
0
votes
1answer
165 views

ngModel' deep objects creation mechanism

I want to use angular' mechanism for deep property nesting , something that ng-model directive is using. I mean we can create very "deep" object in a scope by writing : ...
0
votes
2answers
158 views

How share Service dynamic data between Controllers and Directives

I'd like to know what pattern to use, if I need my Service to share it's dynamic data between Controller, Directives, etc. The reason I mention dynamic, is because I'd like to load new data and this ...
0
votes
2answers
1k views

Angularjs - Declaring factory with a single object with a nested array - getting ReferenceError: … is not defined

I have a factory with several different methods and I am trying to declare an object that has an array nested in it. That one nested array will be the main driving force for my app and it will have ...
0
votes
1answer
377 views

Using angularjs service ($cookies) in factory registered using couchpotato

I'm using angularjs with couchpotato for help with lazy loading. My question is how do I reference angularjs services like $http, $cookies in my service registered using couchpotato? The normal ...
0
votes
3answers
2k views

$watch not working on variable from other controller?

I have one controller which displays a checklist, and stores the selection in an array. My other controller runs an $http.get on the array from the first controller. How do I set a $watch so that ...