我成功添加了一个自定义模板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...
} );
}
};
关于什么在这里打破缩小的想法?谢谢!
答案 0 :(得分:0)
当您缩小$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],
//...