md 对话框不工作
md dialog not working
我是 angular material 的新手,我正在尝试使 $md-Dialog 服务正常工作。我正在使用 angular material 的演示,但不知何故我似乎无法正确使用。我需要添加什么才能使其正常工作/我做错了什么。
演示
https://material.angularjs.org/latest/api/service/$mdDialog
我的html
<div ng-controller="myController">
<md-button ng-click="showAlert()" class="md-raised md-warn">Custom Dialog</md-button>
</div>
我的JS
app.controller('myController', ['$scope', '$mdToast', '$animate', '$mdDialog', '$mdMedia', function ($scope, $mdToast, $mdDialog,$animate, $mdMedia ) {
var alert;
$scope.showAlert = showAlert;
// Internal method
function showAlert() {
alert = $mdDialog.alert({
title: 'Attention',
textContent: 'This is an example of how easy dialogs can be!',
ok: 'Close'
});
$mdDialog
.show( alert )
.finally(function() {
alert = undefined;
});
}
}
这是一个很常见的问题,但是注入数组中模块的顺序必须与函数参数中模块的顺序相匹配。
改变这个:
app.controller('myController',
['$scope', '$mdToast', '$animate', '$mdDialog', '$mdMedia',
function ($scope, $mdToast, $mdDialog, $animate, $mdMedia )
为此:
app.controller('myController',
['$scope', '$mdToast', '$animate', '$mdDialog', '$mdMedia',
function ($scope, $mdToast, $animate, $mdDialog, $mdMedia )
实际上,您不应该手动指定注入名称。使用在 Grunt 和 Gulp
中都可用的 ng-annotate
https://github.com/olov/ng-annotate
https://github.com/johnpapa/angular-styleguide/blob/master/a1/README.md#style-y101
我是 angular material 的新手,我正在尝试使 $md-Dialog 服务正常工作。我正在使用 angular material 的演示,但不知何故我似乎无法正确使用。我需要添加什么才能使其正常工作/我做错了什么。
演示 https://material.angularjs.org/latest/api/service/$mdDialog
我的html
<div ng-controller="myController">
<md-button ng-click="showAlert()" class="md-raised md-warn">Custom Dialog</md-button>
</div>
我的JS
app.controller('myController', ['$scope', '$mdToast', '$animate', '$mdDialog', '$mdMedia', function ($scope, $mdToast, $mdDialog,$animate, $mdMedia ) {
var alert;
$scope.showAlert = showAlert;
// Internal method
function showAlert() {
alert = $mdDialog.alert({
title: 'Attention',
textContent: 'This is an example of how easy dialogs can be!',
ok: 'Close'
});
$mdDialog
.show( alert )
.finally(function() {
alert = undefined;
});
}
}
这是一个很常见的问题,但是注入数组中模块的顺序必须与函数参数中模块的顺序相匹配。
改变这个:
app.controller('myController',
['$scope', '$mdToast', '$animate', '$mdDialog', '$mdMedia',
function ($scope, $mdToast, $mdDialog, $animate, $mdMedia )
为此:
app.controller('myController',
['$scope', '$mdToast', '$animate', '$mdDialog', '$mdMedia',
function ($scope, $mdToast, $animate, $mdDialog, $mdMedia )
实际上,您不应该手动指定注入名称。使用在 Grunt 和 Gulp
中都可用的 ng-annotatehttps://github.com/olov/ng-annotate
https://github.com/johnpapa/angular-styleguide/blob/master/a1/README.md#style-y101