FAQ Database Discussion Community


Angular: Optionally configure a service

angularjs,angularjs-provider
I have a service that has an internal list of directive names (lets call it listService). In the spirit of loosely coupled applications I want other modules to be able to add their own directives to that list instead of statically defining it in the service module. I understand that...

Wait for Provider to finish before entering State

angularjs,angular-ui-router,angularjs-injector,angularjs-provider
I'm trying to wait for the provider to finish initializing before ui-router goes on to load the state. Every time you enter the state the camera should be enabled, and whenever it is left disabled again. I put this into a provider because it needs to be usable at the...

How to inherit from base provider (not the provider factory)?

angularjs,prototypal-inheritance,angularjs-provider
Say I have this base provider: angular.module('app').provider('BaseClient', function () { this.setSomething = function (something) { // Store `something` somewhere return this; }; }); And now these 2 other sub-providers: angular.module('app').provider('ClientA', function () { this.$get = function () { return { foo: function () { console.log('FOO', /* Read `something`, needs to...

Trigger $modal.open from app.js

javascript,angularjs,angularjs-scope,angularjs-controller,angularjs-provider
My app.js looks something like this. I need to handle the AJAX errors globally. This code works fine if I were to use only console.log. However, I need to trigger a modal dialog by using $modal, but not sure how to implement that. Any help is appreciated. Thank you! define(['jquery','angularAMD',...

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

angularjs,angularjs-service,angularjs-factory,angularjs-provider
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 a controller that depends on it myApp.controller('myCtrl', function(myService) { $scope.incr = function() { myService.increment(); }; } And...

AngularJS inject $http into config for angular-translate

angularjs,angular-translate,angularjs-provider
I'm using angular-translate module and am trying to inject all my translations that are on server with $http. I use a provider and I know that only i can inject dependencies through $get but I can't call that function from my provider. I need to know if i can do...

How to create any kind of immutable providers in AngularJS

angularjs,immutability,angularjs-provider
Consider the following example: angular.module('demo') .service('MyService', function () { this.fn = function () { console.log('MyService:fn'); }; }) .factory('MyFactory', function () { function fn() { console.log('MyFactory:fn'); } return { fn: fn }; }) .value('MyValue', { fn: function () { console.log('MyValue:fn'); } }) .constant('MyConstant', { fn: function () { console.log('MyConstant:fn'); } })...

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

angularjs,dependency-injection,angularjs-service,angularjs-factory,angularjs-provider
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 $scope.feeDay = 59; ... // the identical functions $scope.getMinutes = function(minutes) { var duration =...

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

angularjs,angularjs-service,ngroute,angularjs-provider
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 routeProvider configuration. I created a constant,...