Search Posts

Category: dependency-injection

Check if a dependency can be loaded into an AngularJS module

I have an AngularJS application with a plugin system. A plugin might or might not be installed and I need to know if that plugin can be loaded. In the plugin registers a factory like this: const module = angular.module(‘myplugin’, []); module.factory(‘myplugin’, function() { return function() { // do stuff } } In the application, I have: const module = angular.module(‘myapp’, [‘myplugin’]); module.controller(‘somecontoller’, function(myplugin) { myplugin(); // do stuff } If myplugin is does not […]

TypeError: XXX undefined with AngularJS $inject Property annotation

Angular UI Grid Get Cell Vaule I am using angular grid ui and I am trying to get the vaule of cell based on the row and column using getCellValue. I am getting the error Unable to get property ‘$$undefined’ of undefined or null reference How do I get the vaule from a cell based on the row and the column? angular.module(‘app’, [‘ngAnimate’, ‘ngTouch’, ‘ui.grid’,’ui.grid.resizeColumns’,’ui.grid.pinning’,’ui.grid.grouping’, ‘ui.grid.moveColumns’,’ui.grid.exporter’,’ui.grid.selection’,’ui.grid.selection’, ‘ui.grid.cellNav’]).controller(‘MainCtrl’, MainCtrl); MainCtrl.$inject = [‘$http’, ‘uiGridConstants’,’$interval’,’$scope’]; function MainCtrl($http, uiGridConstants,$scope) […]

TypeError: XXX undefined with AngularJS inline array annotation

Im making an AngularJS Application and Im trying to insert JSONwebtoken into the headers, but I can’t figure out what’s wrong with my code. Can you guys help me out? My application config: application.config([‘$routeProvider’,’$httpProvider’, ‘$locationProvider’, function($routeProvider, $locationProvider, $localStorage, $window, $httpProvider) { $httpProvider.interceptors.push(‘AuthInterceptors’); }]); And my AuthInterceptors factory: application.factory(“AuthInterceptors”, function(AuthToken) { var authInterceptorsFactory = {}; authInterceptorsFactory.request = function(config) { var token = AuthToken.getToken(); if(token) config.headers[‘x-access-token’] = token; return config; }; return authInterceptorsFactory; }); Thanks guys! Source: […]

angular 1.5 passes undefined value to a controler after state.Provider "resolve"

I have this code: app.js var promptoWeb = angular.module(‘promptoWeb’, [‘ngMaterial’, ‘ngAnimate’, ‘ngMessages’, ‘ngAria’, ‘ui.router’, ‘ui.sortable’, ‘ngFileUpload’]); (function (app) { app.factory(‘env’, function () { var domain = {domain: “http://localhost:8860/Elton”}; return domain; }); app.config([‘$stateProvider’, ‘$urlRouterProvider’, ‘$compileProvider’, function ($stateProvider, $urlRouterProvider, $compileProvider) { self = this; $compileProvider.preAssignBindingsEnabled(true); $urlRouterProvider.otherwise(‘/’); $stateProvider.state(‘home’, { url: ‘/’, template: ‘<home-component></home-component>’, component: ‘homeComponent’, params: { selectedFilter: undefined }, resolve: { ldapGroup: function (authorizationService) { return authorizationService.getLdapGroup() === ‘WazeAdOps’; } } }) }]); })(promptoWeb); and home-component.js (function […]

Webpack doesn’t add dependencies in AngularJs using the require() method

I probably have problem with webpack configuration, because the require() method in AngularJS DI doesn’t work correctly. In my app use AngularJS, Webpack and ES6. I’m trying to add a library angular-formly-templates-bootstrap. In the source code on GitHub I see the dependency added with: const ngModule = angular.module(ngModuleName, [require(‘angular-formly’)]); After installing the library using Npm in the file I can see: var ngModule = angular.module(ngModuleName, [__webpack_require__(4)]); Unfortunately, firing this code returns me an error: Uncaught […]

angular: resolving circular dependency in services

how to angular: resolving circular dependency in services I’m struggling with this error on my angular app. I have a service (Service A) that depends on another service (service B). Now Service B needs to call Service A, and this is causing circular dependency and I’m getting ‘Can’t resolve all parameters for Service A’. I tried creating service C that calls Service A and injecting that into Service B, but the error is still there. […]

How do I use an external library in an AngularJS Unit Test

how to How do I use an external library in an AngularJS Unit Test I have a unit test which receives an array of objects as the result and I want to use an external library (such as underscore.js) to check said objects, but I can’t seem to figure out how to inject underscore. Does it go in the call like so? it(“My Test”, function(_) {/* Test code here */}); I’m not trying to mock […]

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

Next Page »