AngularJS错误[$ injector:unpr]未知提供程序:在IE11中 [英] AngularJS error [$injector:unpr] Unknown provider: in IE11

查看:46
本文介绍了AngularJS错误[$ injector:unpr]未知提供程序:在IE11中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里也找不到Google的帮助.

I couldn't find help in google neither here.

我是Angular的新手,仅在IE11及以下版本中遇到此错误.

I'm new to Angular and I'm facing this error only in IE11 and below.

我得到的错误是: 在IE中显示的控制台错误

我的IE是葡萄牙语,因此第一个错误的翻译是:不可能获取未定义或为null的"getAttribute"属性

My IE is in portuguese so the translate of the first error is: it's not possible to get property of "getAttribute" of undefined or null

这是我的app.config.js文件

this is my app.config.js file

// Checking if an optional module is registered.
// If it's not, register an empty one to prevent errors.
(function(optDeps){
	optDeps.forEach(function(dep){
		try{
			angular.module(dep);
		}catch(e){
			angular.module(dep, []);
		}
	})
})(['ui.carousel', 'ui.mask', 'vAccordion', 'ngAnimate']);

angular

.module('poletto', [
	// Third party
	'smoothScroll',
	'ui.carousel',
	'ui.mask',
	'vAccordion',
	'ngAnimate',
	
	// Components
	'poletto.components',

	// Controllers
	'poletto.controllers',

	// Directives
	'poletto.directives',

	// Factories
	'poletto.factories',

	// Filters
	'poletto.filters',

	// Services
	'poletto.services'
])

.constant('CONSTANTS', {
	BASE_URL: document.currentScript.getAttribute('data-base-url')
})

.config(function($httpProvider){
	$httpProvider.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
})

.config(function($locationProvider){
	if(window.history.pushState){
		$locationProvider.html5Mode({ enabled: true, requireBase: false, rewriteLinks: false });
	}
})

// Extending JQLite with a function that find nodes by className
.run(function(){
	angular.element.prototype.findBySelector = function(selector){
		var matches = [];
		
		for(key in this){
			// Pushing only HTMLElement's
			if(this[key].nodeType){
				// NodeList to array
				var results = Array.prototype.slice.call(this[key].querySelectorAll(selector));

				matches.push.apply(matches, results);
			}
		}

		return angular.element(matches);
	};
})

我已经搜索过Google并尝试了一些解决方案,例如:

I've searched google and tryied some solutions such as:

  • 添加<meta http-equiv="X-UA-Compatible" content="IE=11" />

将我所有的声明都包装在:

wrap all my declarations in:

(function (angular) { "use strict"; //code }(window.angular));

(function (angular) { "use strict"; //code }(window.angular));

  • 将此添加到html标记中: <html lang="pt-br" xmlns:ng="http://angularjs.org">

  • add this in html tag: <html lang="pt-br" xmlns:ng="http://angularjs.org">

我也找不到任何有角度的polyfills,也没有src/文件夹,但是我在类似的问题中也看到了有角度的2.

Also I couldn't find any angular polyfills neither src/ folder, wich I saw in a similar question with angular 2.

我不知道应该把我的文件放在这里,因此,如果您需要更多信息,可以问我,我会更新问题.

I don't know wich file I should put here, so if you need some more info, you can ask me and I update the question.

谢谢!

推荐答案

不幸的是, document.currentScript不支持IE ,并且无法进行多填充,因此无法做到这一点.也许,您可以将基本url嵌入其他位置,或者在脚本中添加id并在旧式javascript中进行检索.

Unfortunately document.currentScript is not supported on IE and can't be polyfilled so it can't done that way. Perhaps, you can embed the base url somewhere else or maybe add an id to your script and retrieve it in old school javascript.

<script id="main" data-base-url="https://my-api.com"></script>

然后像这样检索它:

var currentScript = document.getElementById('main');

在您的CONSTANTS提供程序中,您可以执行以下操作:

In your CONSTANTS provider you can do something like this:

.constant('CONSTANTS', {
    BASE_URL: document.getElementById('main').getAttribute('data-base-url')
})

这篇关于AngularJS错误[$ injector:unpr]未知提供程序:在IE11中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆