128
votes
3answers
21k 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?
9
votes
3answers
242 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 ...
18
votes
5answers
3k 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 ...
3
votes
1answer
163 views

Angular Service Defination: 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 ...
3
votes
1answer
188 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 ...
2
votes
2answers
152 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', ...
14
votes
2answers
5k 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 ...
12
votes
2answers
2k 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; } }) I would like to test it from the JavaScript console ...
2
votes
3answers
2k 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: ...
2
votes
1answer
3k 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

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 ...
2
votes
1answer
62 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
2answers
193 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 ...
1
vote
1answer
201 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
23 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 ...

15 30 50 per page