Angular mdDialog 控制器代码在缩小时失败

Angular mdDialog controller code fails when minified

我成功添加了自定义模板 mdDialog 以请求名称和单击元素时弹出的布尔(来自复选框)对话框。

然而,虽然它在开发中运行良好,但在生产中却失败了,因为构建过程缩小了 js 代码。我在 SO 中找到了很多关于此问题的示例,但其中 none 强调了如何解决我的问题,在大多数情况下,这是一个解决方案或易于掌握的问题。我的代码是:

function DialogController ( $scope, $mdDialog, gsheet, name ) {
  $scope.name = name;
  $scope.gsheet = gsheet;

  $scope.cancel = function () {
    $mdDialog.cancel ();
  };

  $scope.create = function ( name, gsheet ) {
    $mdDialog.hide ( { 'name': name, 'createSheet': gsheet ? gsheet : false } );
  };
}

function openNewDataSourceDialog ( ev ) {
  if ( !$rootScope.driveAuth ) {
    $rootScope.$emit ( 'requestMoreAuth' );
  }
  else {

    var confirm = $mdDialog.prompt ( {
      templateUrl: "app/main/data-sources/data-sources-dialog.tmpl.html",
      parent: angular.element ( document.body ),
      clickOutsideToClose: true,
      targetEvent: ev,
      controller: DialogController,
      fullscreen: false,
      scope: $scope,
      preserveScope: true,
      locals: {
        name: "",
        gsheet: true
      }
    } );

    $mdDialog.show ( confirm ).then ( function ( result ) {
      //create something...
    }, function () {
      //dont create anything...
    } );
  }
};

关于什么打破了这里的缩小有什么想法吗?谢谢!

当您还缩小 $mdDialog 名称时,通常会发生这种情况。为其添加Dependency Injection

你的情况:

      var confirm = $mdDialog.prompt ( {
      templateUrl: "app/main/data-sources/data-sources-dialog.tmpl.html",
      parent: angular.element ( document.body ),
      clickOutsideToClose: true,
      targetEvent: ev,
      controller: ['$scope', '$mdDialog', 'gsheet', 'name', 
           function ($scope, $mdDialog, gsheet, name) { /* ... */}],
      fullscreen: false,
      scope: $scope,
      preserveScope: true,
      locals: {
        name: "",
        gsheet: true
      }
    } );

或者:

//...
controller: ['$scope', '$mdDialog', 'gsheet', 'name', DialogController],
//...