我是 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;
});
}
}
最佳答案
这是一个非常常见的问题,但是注入(inject)数组中的模块顺序必须与函数参数中的模块顺序相匹配。
更改此:
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 )
关于angularjs - md 对话框不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36181859/