精简JavaScript导致角度注射器错误 [英] Angular injector error with minified JavaScript

查看:74
本文介绍了精简JavaScript导致角度注射器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在努力寻找解决此问题的方法:

I have been struggling to find a solution for this problem:

我正在网站上使用Angular.js。

I am using Angular.js on my site.

我使用CoffeeScript在Visual Studios 2012中编写我的JavaScript。当我保存CoffeeScript时,将同时保存JavaScript文件的缩小版本和未缩小版本。

I use CoffeeScript to write my JavaScript in Visual Studios 2012. When I save my CoffeeScript - both a minified and un-minified version of the JavaScript file is saved.

在我的网页上使用任何缩小版本的JavaScript文件时,我始终收到此错误:

While using any minified version of JavaScript files on my webpage I keep getting this error:

错误:$ injector:unpr
未知提供者
未知提供程序:nProvider<-n
此错误是由于$ injector无法解析所需的依赖关系而导致的。要解决此问题,请确保正确定义了依赖项并对其进行了拼写。例如:

Error: $injector:unpr Unknown Provider Unknown provider: nProvider <- n This error results from the $injector being unable to resolve a required dependency. To fix this, make sure the dependency is defined and spelled correctly. For example:

如果我不使用缩小版,一切都会正常。

If I don’t use the minified version everything works fine.

这是我的方式使用angular在每个JavaScript文件中声明我的App

Here is how I use angular to declare my App in each JavaScript file

(function() {
  var myApp;

  myApp = angular.module("myApp", ['uploaddirective']);

  myApp.controller("videoController", function($scope, $http, $compile) {

有人可以帮助我解决此问题吗?

Can anyone help me to resolve this issue?

推荐答案

使用数组符号进行最小化安全依赖注入:

Use array notation for minification-safe dependency injection:

myApp.controller("videoController", ['$scope', '$http', '$compile', function($scope, $http, $compile) {

另一种选择是使用构建任务为您自动注释注射:

Another option is to use build task to automatically annotate injections for you:

// @ngInject
myApp.controller("videoController", function($scope, $http, $compile) {

您将需要咕unt声或吞咽声为此,例如 ngAnnotate

You will need grunt or gulp plugin for this, like ngAnnotate.

https://docs.angularjs.org/guide/di

这篇关于精简JavaScript导致角度注射器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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