简体   繁体   English

grunt构建后未找到/未定义变量(uglify)

[英]variable not found / undefined after grunt build (uglify)

I am using AngularJS for building a simple app with a map. 我正在使用AngularJS来构建带有地图的简单应用程序。 As the main ctrl had too many logic I build a second controller for the navbar. 由于主ctrl逻辑太多,因此我为导航栏构建了第二个控制器。 Until here everything worked fine. 到这里为止一切正常。 Now I outsourced the map.on('zoomend' ... ) function when refactoring the main controller. 现在,当重构主控制器时,我将map.on('zoomend'...)函数外包了。

The problem now is, that when the navbar controller file is minified (through grunt build uglify) I get the following error: 现在的问题是,当导航栏控制器文件最小化(通过grunt build uglify)时,出现以下错误:

Cannot read on of undefined 无法读取未定义的

That means, map is undefined even though it is declared at the top of the file AND I do not have the problem on localhost (grunt serve). 这意味着,即使在文件的顶部声明了地图,地图也是未定义的,而且我在本地主机(grunt服务)上也没有问题。

Navbar Ctrl: 导航栏Ctrl:

'use strict';
angular.module('angularMapApp').controller('navbarController', navbarController);
navbarController.$inject = ['$scope', '$mdSidenav', 'helper', 'RespondService', 'shipTypes'];

function navbarController($scope, $mdSidenav, helper, RespondService, shipTypes) {
  var map = RespondService.getMap();
 map.on('zoomend', function() {
    timestamp = RespondService.getTimestamp();
    selectedShipTypes = RespondService.getSelectedShipTypes();
    selectedShipState = RespondService.getSelectedShipState();
    showGrid = RespondService.getShowGrid();
    helper.loadAndShowShipMarkers(timestamp, selectedShipTypes, selectedShipState, showGrid, map).then(function(results) {
      $scope.numberOfShips = results;
      RespondService.setNumberOfShips($scope.numberOfShips);
    });
  });

So this is a short version of my controller. 这是我的控制器的简短版本。 The grunt file is still the same as created with yeoman. grunt文件仍然与使用yeoman创建的文件相同。 I too logged the map value at the top of the file, and there it has a value. 我也将映射值记录在文件的顶部,并且在那里有一个值。 However using 'map.on' might not work. 但是,使用“ map.on”可能不起作用。

Maybe anyone can help me with that. 也许有人可以帮助我。

Your $inject seems to be correct, so minify should work fine for angular injection. 您的$ inject似乎是正确的,因此minify可以很好地用于角度注入。 It looks like var map is loading data from RespondService.getMap(). 看起来var map正在从RespondService.getMap()加载数据。 What do you expect to get from that function? 您希望从该功能中得到什么? You might want to put a break point and see if what you expecting is being returned. 您可能要设置一个断点,看看是否返回了您期望的结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM