use*_*912 2 coffeescript angularjs
我一直在努力寻找解决这个问题的方法:
\n\n我在我的网站上使用 Angular.js。
\n\n我使用 CoffeeScript 在 Visual Studios 2012 中编写 JavaScript。当我保存 CoffeeScript 时,JavaScript 文件的缩小版本和未缩小版本都会被保存。
\n\n在我的网页上使用 JavaScript 文件的任何缩小版本时,我不断收到此错误:
\n\n错误: $injector:unpr\n未知提供程序\n未知提供程序: nProvider <- n\n此错误是由于 $injector 无法解析所需的依赖项而导致的。要解决此问题,请确保依赖项的定义和拼写正确。例如:
\n\n如果我不\xe2\x80\x99t 使用缩小版本,一切正常。
\n\n以下是我如何使用 Angular 在每个 JavaScript 文件中声明我的应用程序
\n\n(function() {\n var myApp;\n\n myApp = angular.module("myApp", [\'uploaddirective\']);\n\n myApp.controller("videoController", function($scope, $http, $compile) {\nRun Code Online (Sandbox Code Playgroud)\n\n谁能帮我解决这个问题?
\n使用数组表示法进行缩小安全依赖注入:
myApp.controller("videoController", ['$scope', '$http', '$compile', function($scope, $http, $compile) {
Run Code Online (Sandbox Code Playgroud)
另一种选择是使用构建任务自动为您注释注入:
// @ngInject
myApp.controller("videoController", function($scope, $http, $compile) {
Run Code Online (Sandbox Code Playgroud)
为此,您将需要 grunt 或 gulp 插件,例如ngAnnotate。
https://docs.angularjs.org/guide/di
| 归档时间: |
|
| 查看次数: |
1362 次 |
| 最近记录: |