“Uncaught Error:”部署后有angular度

我有一个相当简单的Angular应用程序,在我的开发机器上运行得很好,但是在部署它之后,出现这个错误消息(在浏览器控制台中):

Uncaught Error: [$injector:unpr] http://errors.angularjs.org/undefined/$injector/unpr?p0=tProvider%20%3C-%20t%20%3C-%20%24http%20%3C-%20%24compile

除此之外没有别的消息。 它首先加载页面时发生。

我正在运行ASP.NET MVC5,Angular 1.2RC3,并通过git推送到Azure。

谷歌search没有发现任何有趣的事情。

有什么build议么?

编辑:

我正在使用TypeScript,并使用$injectvariables定义我的依赖关系,例如:

 export class DashboardCtrl { public static $inject = [ '$scope', '$location', 'dashboardStorage' ]; constructor( private $scope: IDashboardScope, private $location: ng.ILocationService, private storage: IDashboardStorage) { } } 

我相信应该(或者打算)绕过在缩小过程中出现的局部variables重命名问题,并且可能导致这个错误。

也就是说,这显然与缩小过程有关,因为当我在我的开发机器上设置BundleTable.EnableOptimizations = true时,我可以重现它。

如果你按照你的链接,它会告诉你$注射器的错误结果不能解决你的依赖关系。 这是一个常见的问题,当JavaScript被缩小/丑化/无论你正在做的生产。

问题是当你有一个控制器,

 angular.module("MyApp").controller("MyCtrl", function($scope, $q) { // your code }) 

缩小将$scope$q变成随机variables,这些variables不会告诉angular色注入的内容。 解决scheme是声明你的依赖像这样:

 angular.module("MyApp") .controller("MyCtrl", ["$scope", "$q", function($scope, $q) { // your code }]) 

这应该解决你的问题。

只是重新迭代,我所说的一切都在错误信息提供给你的链接上。

自己也遇到了同样的问题,但是我的控制器定义与上面有些不同。 对于像这样定义的控制器:

 function MyController($scope, $http) { // ... } 

在声明后面添加一行代表控制器实例化时要注入哪些对象:

 function MyController($scope, $http) { // ... } MyController.$inject = ['$scope', '$http']; 

这使得它小型化安全。

当控制器或指令未指定为依赖项和函数的数组时,会发生此问题。 例如

 angular.module("appName").directive('directiveName', function () { return { restrict: 'AE', templateUrl: 'calender.html', controller: function ($scope) { $scope.selectThisOption = function () { // some code }; } }; }); 

缩小时将传递给控制器​​函数的'$ scope'replace为单个字母variables名称。 这将使angular色无法依赖。 为了避免这种情况,将依赖项名称与函数一起作为数组传递。

 angular.module("appName").directive('directiveName', function () { return { restrict: 'AE', templateUrl: 'calender.html' controller: ['$scope', function ($scope) { $scope.selectThisOption = function () { // some code }; }] }; }); 

如果你已经为angular app \ resources \ directives和其他东西分离了文件,那么你可以像这样closures你的angular色应用程序包的缩小(在bundleconfiguration文件中使用新的Bundle()而不是ScriptBundle()):

 bundles.Add( new Bundle("~/bundles/angular/SomeBundleName").Include( "~/Content/js/angular/Pages/Web/MainPage/angularApi.js", "~/Content/js/angular/Pages/Web/MainPage/angularApp.js", "~/Content/js/angular/Pages/Web/MainPage/angularCtrl.js")); 

angular度应用程序将出现在未修改的包中。

在控制器中添加$ http,$ scope服务,有时候如果缺less这些错误就会发生。

如果你已经为angular app \ resources \ directives和其他东西分离了文件,那么你可以像这样closures你的angular色应用程序包的缩小(在bundleconfiguration文件中使用新的Bundle()而不是ScriptBundle()):