Search Posts

Category: dependency-injection

Intercept each http calls an ES6 approach

I wanted to write injectable service in Angular which can intercept all ajax calls. Basically before ajaxStart and after after finished. I am able to achieve by this code-snippets. But I am able to achieve it using es5 syntax. How I can do the same thing by extending XMLHttpRequest which is shown in file no: 3? 1) http-interceptor.ts import { Injectable, Component, OnInit } from ‘@angular/core’; import { BehaviorSubject } from ‘rxjs/BehaviorSubject’; interface AjaxRequest { […]

Unable to inject one factory into another factory in angularjs 1 and send token to angularjs application

I have an application which is a php application. I want this application to reside in my primary domain (primarydomain.com purposely for Single-Sign-On(to manage account details). Every user login here and upon successful login, redirect to one of my app hosted on a first.primarydomain.com. Upon redirection, authorize the user by checking if the user really logged in. Now I have hosted an angularjs application in first.primarydomain.com In my angularjs project, I have created a factory […]

AngularJs injection error

My sample, very basic, skeleton app works just fine. Then I tried to add @MaximShoustin answer from this question – Plunk here. And I get jquery-3.1.1.min.js:2 Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.5.0/$injector/modulerr?p0=inspinia&p1=Error%3A%20%5B%24injector%3Amodulerr%5D%20http%3A%2F%2Ferrors.angularjs.org%2F1.5.0%2F%24injector%2Fmodulerr%3Fp0%3Doc.lazyLoad%26p1%3DError%253A%2520%255B%2524injector%253Anomod%255D%2520http%253A%252F%252Ferrors.angularjs.org%252F1.5.0%252F%2524injector%252Fnomod%253Fp0%253DngSanitize%250A%2520%2520%2520%2520at%2520http%253A%252F%252Flocalhost%252Fa%252Fjs%252Fangular%252Fangular.min.js%253A6%253A416%250A%2520%2520%2520%2520at%2520http%253A%252F%252Flocalhost%252Fa%252Fjs%252Fangular%252Fangular.min.js%253A25%253A136%250A%2520%2520%2520%2520at%2520b%2520(http%253A%252F%252Flocalhost%252Fa%252Fjs%252Fangular%252Fangular.min.js%253A24%253A188)%250A%2520%2520%2520%2520at%2520Object.module%2520(http%253A%252F%252Flocalhost%252Fa%252Fjs%252Fangular%252Fangular.min.js%253A24%253A431)%250A%2520%2520%2520%2520at%2520u%2520(http%253A%252F%252Flocalhost%252Fa%252Fjs%252Fplugins%252Foclazyload%252Fdist%252FocLazyLoad.min.js%253A8%253A2925)%250A%2520%2520%2520%2520at%2520Object.n%2520%255Bas%2520forEach%255D%2520(http%253A%252F%252Flocalhost%252Fa%252Fjs%252Fangular%252Fangular.min.js%253A7%253A355)%250A%2520%2520%2520%2520at%2520u%2520(http%253A%252F%252Flocalhost%252Fa%252Fjs%252Fplugins%252Foclazyload%252Fdist%252FocLazyLoad.min.js%253A8%253A2994)%250A%2520%2520%2520%2520at%2520http%253A%252F%252Flocalhost%252Fa%252Fjs%252Fplugins%252Foclazyload%252Fdist%252FocLazyLoad.min.js%253A8%253A3048%250A%2520%2520%2520%2520at%2520Object.n%2520%255Bas%2520forEach%255D%2520(http%253A%252F%252Flocalhost%252Fa%252Fjs%252Fangular%252Fangular.min.js%253A7%253A355)%250A%2520%2520%2520%2520at%2520u%2520(http%253A%252F%252Flocalhost%252Fa%252Fjs%252Fplugins%252Foclazyload%252Fdist%252FocLazyLoad.min.js%253A8%253A3026)%250A%2520%2520%2520%2520at%2520new%2520%253Canonymous%253E%2520(http%253A%252F%252Flocalhost%252Fa%252Fjs%252Fplugins%252Foclazyload%252Fdist%252FocLazyLoad.min.js%253A8%253A3511)%250A%2520%2520%2520%2520at%2520Object.instantiate%2520(http%253A%252F%252Flocalhost%252Fa%252Fjs%252Fangular%252Fangular.min.js%253A41%253A396)%250A%2520%2520%2520%2520at%2520c%2520(http%253A%252F%252Flocalhost%252Fa%252Fjs%252Fangular%252Fangular.min.js%253A38%253A348)%250A%2520%2520%2520%2520at%2520Object.provider%2520(http%253A%252F%252Flocalhost%252Fa%252Fjs%252Fangular%252Fangular.min.js%253A38%253A290)%250A%2520%2520%2520%2520at%2520d%2520(http%253A%252F%252Flocalhost%252Fa%252Fjs%252Fangular%252Fangular.min.js%253A39%253A234)%250A%2520%2520%2520%2520at%2520http%253A%252F%252Flocalhost%252Fa%252Fjs%252Fangular%252Fangular.min.js%253A39%253A340%250A%2520%2520%2520%2520at%2520n%2520(http%253A%252F%252Flocalhost%252Fa%252Fjs%252Fangular%252Fangular.min.js%253A7%253A355)%250A%2520%2520%2520%2520at%2520g%2520(http%253A%252F%252Flocalhost%252Fa%252Fjs%252Fangular%252Fangular.min.js%253A39%253A135)%250A%2520%2520%2520%2520at%2520http%253A%252F%252Flocalhost%252Fa%252Fjs%252Fangular%252Fangular.min.js%253A39%253A304%250A%2520%2520%2520%2520at%2520n%2520(http%253A%252F%252Flocalhost%252Fa%252Fjs%252Fangular%252Fangular.min.js%253A7%253A355)%250A%2520%2520%2520%2520at%2520g%2520(http%253A%252F%252Flocalhost%252Fa%252Fjs%252Fangular%252Fangular.min.js%253A39%253A135)%250A%2520%2520%2520%2520at%2520fb%2520(http%253A%252F%252Flocalhost%252Fa%252Fjs%252Fangular%252Fangular.min.js%253A43%253A164)%250A%2520%2520%2520%2520at%2520c%2520(http%253A%252F%252Flocalhost%252Fa%252Fjs%252Fangular%252Fangular.min.js%253A20%253A449)%250A%2520%2520%2520%2520at%2520Ac%2520(http%253A%252F%252Flocalhost%252Fa%252Fjs%252Fangular%252Fangular.min.js%253A21%253A259)%250A%2520%2520%2520%2520at%2520fe%2520(http%253A%252F%252Flocalhost%252Fa%252Fjs%252Fangular%252Fangular.min.js%253A20%253A69)%250A%2520%2520%2520%2520at%2520HTMLDocument.%253Canonymous%253E%2520(http%253A%252F%252Flocalhost%252Fa%252Fjs%252Fangular%252Fangular.min.js%253A306%253A372)%250A%2520%2520%2520%2520at%2520j%2520(http%253A%252F%252Flocalhost%252Fa%252Fjs%252Fjquery%252Fjquery-3.1.1.min.js%253A2%253A29948)%250A%2520%2520%2520%2520at%2520k%2520(http%253A%252F%252Flocalhost%252Fa%252Fjs%252Fjquery%252Fjquery-3.1.1.min.js%253A2%253A30262)%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%2Fa%2Fjs%2Fangular%2Fangular.min.js%3A6%3A416%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%2Fa%2Fjs%2Fangular%2Fangular.min.js%3A40%3A60%0A%20%20%20%20at%20n%20(http%3A%2F%2Flocalhost%2Fa%2Fjs%2Fangular%2Fangular.min.js%3A7%3A355)%0A%20%20%20%20at%20g%20(http%3A%2F%2Flocalhost%2Fa%2Fjs%2Fangular%2Fangular.min.js%3A39%3A135)%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%2Fa%2Fjs%2Fangular%2Fangular.min.js%3A39%3A304%0A%20%20%20%20at%20n%20(http%3A%2F%2Flocalhost%2Fa%2Fjs%2Fangular%2Fangular.min.js%3A7%3A355)%0A%20%20%20%20at%20g%20(http%3A%2F%2Flocalhost%2Fa%2Fjs%2Fangular%2Fangular.min.js%3A39%3A135)%0A%20%20%20%20at%20fb%20(http%3A%2F%2Flocalhost%2Fa%2Fjs%2Fangular%2Fangular.min.js%3A43%3A164)%0A%20%20%20%20at%20c%20(http%3A%2F%2Flocalhost%2Fa%2Fjs%2Fangular%2Fangular.min.js%3A20%3A449)%0A%20%20%20%20at%20Ac%20(http%3A%2F%2Flocalhost%2Fa%2Fjs%2Fangular%2Fangular.min.js%3A21%3A259)%0A%20%20%20%20at%20fe%20(http%3A%2F%2Flocalhost%2Fa%2Fjs%2Fangular%2Fangular.min.js%3A20%3A69)%0A%20%20%20%20at%20HTMLDocument.%3Canonymous%3E%20(http%3A%2F%2Flocalhost%2Fa%2Fjs%2Fangular%2Fangular.min.js%3A306%3A372)%0A%20%20%20%20at%20j%20(http%3A%2F%2Flocalhost%2Fa%2Fjs%2Fjquery%2Fjquery-3.1.1.min.js%3A2%3A29948)%0A%20%20%20%20at%20k%20(http%3A%2F%2Flocalhost%2Fa%2Fjs%2Fjquery%2Fjquery-3.1.1.min.js%3A2%3A30262) at angular.js:38 at angular.js:4526 at n (angular.js:321) at g (angular.js:4487) at fb (angular.js:4409) at c (angular.js:1691) at Ac (angular.js:1712) at fe (angular.js:1606) at HTMLDocument.<anonymous> (angular.js:30423) at j (jquery-3.1.1.min.js:2) at k (jquery-3.1.1.min.js:2) Here’s what ought to be the relevant code to inject $sce and $sanitize (I […]

How to inject service in private constructor

I have an existing code implementing singleton pattern by having private constructor and returning object instance returning the object – export class SingletonFactory { private static factoryInstance = new SingletonFactory(); private constructor() { } public static getInstance() { return SingletonFactory.factoryInstance; } } I need to inject a dependency into this factory. And I changed my code to the following – @Inject(‘MyService’) export class SingletonFactory { private static factoryInstance = new SingletonFactory(); private constructor(private myService : […]

How can I add dependency to the current class using AngularJs and TypeScript?

Let’s say I have a component class as follows; @Component({ selector: “my”, templateUrl: “/app/my.html” }) export class MyComponent extends MyBase { helper: Helper; constructor() { helper = new Helper(this); } } The Helper class lives in another file like this. export class Helper { constructor(protected component: MyBase) { } } It looks like I can’t use dependency injection for my helper class no matter what since it is storing a reference to the component. The […]