Questions tagged [angularjs-provider]

A provider is an object with a $get() method. The injector calls the $get method to create a new instance of a service. The Provider can have additional methods which would allow for configuration of the provider.

59 questions
3410
votes
30 answers

AngularJS: Service vs provider vs factory

What are the differences between a Service, Provider and Factory in AngularJS?
30
votes
3 answers

AngularJS : How should controllers and factories/services be structured with a rich, hierarchical object model?

I read these two great articles: The state of angularjs controllers by Jonathan Creamer and Rethinking AngularJS Controllers by Todd Motto In these articles, the authors talk about the right way to use controllers (making them anemic bridges between…
richard
  • 12,263
  • 23
  • 95
  • 151
11
votes
2 answers

Use resolve with angularjs component

I am trying to resolve a list of customers prior to rendering a page. Here is the state provider reference, where I have the resolve methods. angular.module('app') .config(($stateProvider) => { $stateProvider .state('customers', { …
5
votes
2 answers

How to make a service object that doesn't share its values with controllers that consume it

Let's suppose I create a factory, service, or provider object like so myApp.factory('myService', function() { return { counter: 0, increment: function() { console.log('counter: ' + (this.counter++)) } }; }); And suppose I have…
kane
  • 5,465
  • 6
  • 44
  • 72
5
votes
2 answers

How to make a prototype out of 2 identical controllers in angularjs?

In my app I have 2 almost identical controllers. A lot of functions are the same, so I'd like to prototype them. This is Controller #1: c2gcontroller.js angular.module('c2gyoApp') .controller('C2gCtrl', function($scope) { // some unique stuff …
4
votes
2 answers

Error: [$injector:unpr] Unknown provider: $q. Confused about DI syntax

Snippet 1 does not work. I get Error: [$injector:unpr] Unknown provider: $q /* Snippet 1*/ var mApp = angular.module('MyApp',[]); mApp.provider('authProvider', ['$q', function($q) { this.$get = function(){ authProvider = {}; …
TkNeo
  • 415
  • 1
  • 7
  • 16
3
votes
1 answer

Create unique instance of provider ionic 3

I am creating an Ionic app. I have 3 providers - database provider, portfolio provider and user provider. All 3 are Injectable. I have created it this way because several other pages need to use their function calls (i.e. they should not share the…
3
votes
1 answer

Angularjs : Using common service in different modules

I am trying to use the same service for different modules. There are many modules so i tried to inject them in a parent module. Something like this: var app=angular.module('myapp',['module_1','module_2',....,'module_n']); var…
3
votes
1 answer

How to inject services into a provider with angular 1.3

In every piece of information I can find (including the angular documentation), the way to inject a service into a provider is through the $get method: var myApp = angular.module('myApp', []); myApp.provider('helloWorld', function() { this.$get…
3
votes
1 answer

Angularjs provider with different configurations in different modules

I'd like to know if there is a way of making the configuration of a provider unique not across the entire application, but only across the module that is configuring it. For example, I have a module "core" which contains the definition of a…
Luccas Correa
  • 2,160
  • 2
  • 19
  • 21
2
votes
2 answers

provider not found for underscore

i have an angularjs factory to which i am injecting underscore and application is working fine but when i try to write jasmine test cases on it i am getting an error underscore provider is not found i have my factory…
ashwin
  • 21
  • 1
2
votes
1 answer

How to inject $resource into provider?

I've inherited the following code, and I need to get $resource injected into the service. I'm new to AngularJS and not finding the documentation very helpful. Everything I've tried has failed. Any ideas? (function (angular)…
2
votes
1 answer

How to prevent direct access to properties when inheriting from a base provider?

This is a follow up to How to inherit from base provider (not the provider factory)?. The proposed solution suggests a combination of angular.extend and angular.copy (which can be done with just angular.merge on Angular 1.4) to copy the base…
2
votes
1 answer

AngularJS how to configure Provider between 2 modules?

Please see my proof of concept: http://plnkr.co/edit/y3pzFv?p=preview. How Do I configure Provider between 2 modules? Brief: I am trying to generalize a service and configure multiple instances slightly differently. Right now I have a bunch of…
2
votes
2 answers

Angular "Unkown Provider" - how to use a factory within routeProvider configuration?

While playing around with Angular I try to understand better how to use factory, services, constants, routing and other core concepts. So I build a simple demo app with node, express, jade and angular. Now I would like to use a value inside the…
Rainer
  • 1,067
  • 2
  • 14
  • 29
1
2 3 4