Angular 缩小后应用无法运行(可能是 ng 路由或其他)
Angular app not working when minified (possibly ng route or something else)
我有一个未缩小的应用程序,但是当使用 uglify 组合 angular、angular_routes 和我的 script.js 时,我收到注入器错误。我使用 $inject 为控制器完成了内联注释
这个:
var app = angular.module('app', ['ngRoute']);
mainController.$inject = ['$scope', '$http', '$window', '$location'];
app.controller('mainController', mainController);
function mainController($scope, $http, $window, $location) {
$window.ga('send', 'pageview', { page: $location.url() });
}
我必须对 ng-routes 做些什么吗?或 app.run?这是代码:
app.config(function($routeProvider) {
$routeProvider
// route for the home page
.when('/', {
templateUrl : 'pages/home.html',
controller : 'mainController'
})
app.run部分:
app.run(function ($rootScope, $location) {///
完整代码在这里,如果你想看的话:
http://stephenbreighner.com/script.js
谢谢
Angular 的依赖注入基于参数的名称工作,例如 $scope
。缩小后,它将被称为 non-readable 名称,如 b
,因此 angular 将无法查找应注入的内容。要解决此问题,请使用数组表示法:
app.config(["$routeProvider", function($routeProvider) {
$routeProvider
// route for the home page
.when('/', {
templateUrl : 'pages/home.html',
controller : 'mainController'
})
}])
和
app.run(["$rootScope", "$location", function ($rootScope, $location) {///
我有一个未缩小的应用程序,但是当使用 uglify 组合 angular、angular_routes 和我的 script.js 时,我收到注入器错误。我使用 $inject 为控制器完成了内联注释 这个:
var app = angular.module('app', ['ngRoute']);
mainController.$inject = ['$scope', '$http', '$window', '$location'];
app.controller('mainController', mainController);
function mainController($scope, $http, $window, $location) {
$window.ga('send', 'pageview', { page: $location.url() });
}
我必须对 ng-routes 做些什么吗?或 app.run?这是代码:
app.config(function($routeProvider) {
$routeProvider
// route for the home page
.when('/', {
templateUrl : 'pages/home.html',
controller : 'mainController'
})
app.run部分:
app.run(function ($rootScope, $location) {///
完整代码在这里,如果你想看的话: http://stephenbreighner.com/script.js
谢谢
Angular 的依赖注入基于参数的名称工作,例如 $scope
。缩小后,它将被称为 non-readable 名称,如 b
,因此 angular 将无法查找应注入的内容。要解决此问题,请使用数组表示法:
app.config(["$routeProvider", function($routeProvider) {
$routeProvider
// route for the home page
.when('/', {
templateUrl : 'pages/home.html',
controller : 'mainController'
})
}])
和
app.run(["$rootScope", "$location", function ($rootScope, $location) {///