0

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

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

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...
    } );
  }
};

关于是什么破坏了这里的缩小的任何想法?谢谢!

4

1 回答 1

0

它主要发生在您缩小$mdDialog名称时。为它添加依赖注入

在你的情况下:

      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],
//...
于 2017-08-17T13:08:01.867 回答