标签: angularjs-injector

基于特征检测的AngularJS服务注入

在我的Angular应用程序中,我需要创建一个持久性服务接口,该接口根据浏览器中可用的持久性机制调用具体实现.我正在考虑使用通用storageService实现此功能,该服务调用了解存储机制的特定storageService.

例如,通用storageService将提供以下接口:

angular
    .module('app.storage')
    .factory('storageService', storageService);

function storageService() {
    return {
        saveItem: saveItem,
        getItem: getItem
    }

    ...
}
Run Code Online (Sandbox Code Playgroud)

storageService将有多个实现,例如localStorageService,indexedDbStorageService,webSqlStorageService.

基于浏览器功能动态注入具体存储服务的最佳方法是什么.例如,

if (isWebSqlAvailable()) {
    // inject webSqlStorageService 
}
else if (isIndexedDbAvailable() {
    // inject indexedDbStorageService 
}
else if (isLocalStorageAvailable() {
    // inject localStorageService 
}
Run Code Online (Sandbox Code Playgroud)

angularjs angularjs-injector

4
推荐指数
1
解决办法
206
查看次数

$提供外部配置块

我当然错过了关于喷射器的一些基本观点,但我不明白为什么会这样

angular.module('app').config(function ($provide) {
    ...
});
Run Code Online (Sandbox Code Playgroud)

还有这个

angular.module('app').config(function ($injector) {
    $injector.invoke(function ($provide) { ... });
});
Run Code Online (Sandbox Code Playgroud)

按计划工作,而这一点

app.run(function($provide) {
    ...
});
Run Code Online (Sandbox Code Playgroud)

会扔

错误:[$ injector:unpr]未知提供者:$ provideProvider < - $ provide

如上所述,config与提供者有一些特殊的关系,同时run处理实例,但我不确定使config块如此特殊的东西.

因此,没有办法到达$provide外部config块,例如angular.injector()(尽管它似乎也获得了提供者实例)?

除了好奇之外,这个问题也有一些实际的考虑因素.在1.4中,所有$provide函数都暴露给模块,但1.3的情况并非如此.

internals angularjs angularjs-injector

3
推荐指数
1
解决办法
1464
查看次数

我的Angularjs在哪里缩小错误?错误$ injector

我遇到了恼人的Angular minify问题(我真的希望Angular 2中不存在这个问题)

我已经注释掉了我的所有应用程序模块注入并逐一下载列表以找出问题所在,我想我将其缩小到我的searchPopoverDirectives:

你能看出我做错了什么吗?

原始代码,产生此错误 Unknown provider: eProvider <- e:

(function() { "use strict";

    var app = angular.module('searchPopoverDirectives', [])

    .directive('searchPopover', function() {
        return {
            templateUrl : "popovers/searchPopover/searchPopover.html",
            restrict    : "E",
            scope       : false,
            controller  : function($scope) {

                // Init SearchPopover scope:
                // -------------------------
                var vs = $scope;
                vs.searchPopoverDisplay = false;

            }
        }
    })

})();
Run Code Online (Sandbox Code Playgroud)

然后,我试图[]修复minify问题尝试语法并遇到此错误 Unknown provider: $scopeProvider <- $scope <- searchPopoverDirective:

(function() { "use strict";

    var app = …
Run Code Online (Sandbox Code Playgroud)

javascript minify angularjs angularjs-injector

2
推荐指数
1
解决办法
4329
查看次数

应用程序在 UNMOUNTING 状态下死亡:无法读取未定义的属性“注入器”

我正在使用 Single-Spa-Angular 库构建微前端。我使用“ng add single-spa-angular”创建了三个不同的子应用程序,其中两个应用程序工作正常,但一个应用程序显示以下错误:

Uncaught app2: Application 'app2' died in status UNMOUNTING: Cannot read property 'injector' of undefined
    at http://<HOSTNAME>:4202/main.js:204363:53
Run Code Online (Sandbox Code Playgroud)

Uncaught app2: Application 'app2' died in status SKIP_BECAUSE_BROKEN: In this configuration Angular requires Zone.js
    at new NgZone (http://<HOST>:4202/main.js:68725:19)
    at getNgZone (http://<HOST>:4202/main.js:69414:13)
    at PlatformRef../node_modules/@angular/core/fesm5/core.js.PlatformRef.bootstrapModuleFactory (http://<HOST>:4202/main.js:69312:22)
    at http://<HOST>:4202/main.js:69356:59
Run Code Online (Sandbox Code Playgroud)

谁能帮我吗。

谢谢沙希·布山·维尔玛

single-page-application angularjs-injector angular micro-frontend

1
推荐指数
1
解决办法
6784
查看次数

Angularjs工厂注入错误

我正在使用angularJS,当我注入工厂时,我收到错误:

app.js:

angular.module('myapp', [])
Run Code Online (Sandbox Code Playgroud)

myfactory.js:

angular.module('myapp', [])
.factory('httpService', function($http, $timeout) {

});
Run Code Online (Sandbox Code Playgroud)

控制器:test.js:

angular.module('myapp', [])
.controller('test',  function($scope, $timeout, $sce, $http, httpService) {

  $scope.submit = function() {
  }
});
Run Code Online (Sandbox Code Playgroud)

当我添加httpService我得到错误.一切似乎都是对的,我甚至在所有项目中都使用这个工厂.错误:

angular.min.js:92 Error: [$injector:unpr] http://errors.angularjs.org/1.2.25/$injector/unpr?p0=httpServiceProvider%20%3C-%20httpService
at Error (native)
at http://localhost:81/chah/assets/js/angularjs/angular.min.js:6:450
at http://localhost:81/chah/assets/js/angularjs/angular.min.js:36:202
at Object.c [as get] (http://localhost:81/chah/assets/js/angularjs/angular.min.js:34:305)
at http://localhost:81/chah/assets/js/angularjs/angular.min.js:36:270
at c (http://localhost:81/chah/assets/js/angularjs/angular.min.js:34:305)
at d (http://localhost:81/chah/assets/js/angularjs/angular.min.js:35:6)
at Object.instantiate (http://localhost:81/chah/assets/js/angularjs/angular.min.js:35:165)
at http://localhost:81/chah/assets/js/angularjs/angular.min.js:67:419
at http://localhost:81/chah/assets/js/angularjs/angular.min.js:54:25
Run Code Online (Sandbox Code Playgroud)

javascript angularjs angularjs-factory angularjs-injector

0
推荐指数
1
解决办法
1944
查看次数