Search Posts

Category: dependency-injection

how to inject ionicContentBanner into Jasmine tests

I have a controller which has a bunch of dependencies injected in it. I am able to inject most of them successfully into my jasmine test however, some of my UI specific libraries, like videogular, ionic tinder cards and ionic content banners are failing to inject. This question focus’s on $ionicContentBanner and maybe I can get the rest to work. Here is my controller I am trying to test – I have omitted most of […]

How can inject module and source file in same time?

We have 2 application app1 & app2 app1.js var app1 = angular.module(“app1”, []); app2.js var app2 = angular.module(“app2″, []); app2/index.html <div ng-app=”app2″> <script src=”angular.js”></script> <script src=”app1.js”></script> <script src=”app2.js”></script> </div> Target is inject app1 in app2 we can do it by add app2.requires.push(‘app1′); in app2.js and put <script src=”app1.js”></script> file in app2/index.html. Question is How i can, inject the module and the source file together in same time in app2?. it’s possible? Source: AngularJS

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 […]