2016-03-23 88 views
2

我是新來的角材料,我試圖讓$ md-Dialog服務工作。我正在使用角度材質的演示,但不知怎的,我似乎無法做到。我需要添加什麼才能工作/我做錯了什麼。md對話框不工作

演示 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; 
    }); 
} 
} 

回答

2

這是一個相當普遍的問題,但模塊的注入陣列必須在訂單與您的函數參數中模塊的順序相匹配。

更改此:

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)