gpt4 book ai didi

angulartics - 未知提供者 : $rootElementProvider <- $rootElement <- $location in angulartics. js

转载 作者:行者123 更新时间:2023-12-02 04:53:00 24 4
gpt4 key购买 nike

我在我的项目中使用了 angulartics,但是当我向我的模块添加依赖项时,出现以下错误:

未知提供者:$rootElementProvider <- $rootElement <- $location.

我在 angular.js 之后在 html 中插入了 angulartics.js

它是在.run中生成的:

此处的库代码:https://github.com/luisfarzati/angulartics/issues/203

$location 是好的对象,但是 $rootElementProvider$rootElement 是未定义的。

如何解决这个问题?

最佳答案

我最近遇到了同样的问题,我知道这可能发生的唯一原因是当你手动创建一个 angularjs 注入(inject)器时,它依赖于在引导期间注入(inject) $location 的模块,或者当你试图获取 $location你自己通过那个注入(inject)器。

这个问题实际上与 angulartics 库本身无关,而是与 angular 自己的 $location 服务有关,该服务直接依赖于 $rootElement,该元素是在应用程序引导期间定义的,因此在应用程序启动之前不存在。

如果您遇到角度问题,有一种简单的方法可以解决此问题,那就是从您的应用程序中删除角度作为依赖项并将其添加为 resumeBootstrap 方法的依赖项,这样我们就可以添加更多恢复 Angular 的引导过程时对运行时的依赖。

例如:

angular.module('myApp', [
// array of dependencies without angulartics
]);
var preBootstrapInjector = angular.injector(['ng', 'myApp']);
var $rootScope = preBootstrapInjector.$get('$rootScope');
var myService = preBootstrapInjector.$get('myService');
myService.getDataFromServer()
.then(doSomethingWithThatData)
.then(resumeBootstrap);

function resumeBootstrap(){
// Clean up the custom injector for garbage collection
$rootScope.$destroy();

// Resume Angular's bootstrap process
$(document).ready(function() {
angular.resumeBootstrap([
// dependencies from modules that need $location
'angulartics'
]);
});
}

干杯!

关于angulartics - 未知提供者 : $rootElementProvider <- $rootElement <- $location in angulartics. js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25945909/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com