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 ( 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 Upon redirection, authorize the user by checking if the user really logged in. Now I have hosted an angularjs application in 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]$injector/modulerr?p0=inspinia& 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 […]