从控制器使用$ mdDialog stright

时间:2015-12-13 23:49:42

标签: angularjs angular-material

登录失败时尝试使用$ mdDialog;目前我已经注入$ mdDialog并且我的响应失败了,我添加了以下代码:

$ mdDialog代码:

$mdDialog.show( 
$mdDialog.alert()
.title('Username / password is incorrect')
.textContent(response.message)
.ok('Got it!'));

任何想法我做错了什么?

我的错误

$mdDialog.alert(...).title(...).textContent is not a function

我的控制员(我认为不是必要但只是包住):

(function () {
    'use strict';
    angular
        .module('app')
        .controller('authController', authController);

    authController.$inject = ['$scope','$state','AuthService','$mdDialog'];


    function authController($scope,$state,AuthService,$mdDialog) {

        $scope.login = login;
        $scope.user = {email: 'user', pass: 'pass'};

        function login(){

            this.dataLoading = true;

            AuthService.Login(this.user.email, this.user.pass, function (response) {

                console.log(response);

                if (response.success) {

                    $state.go("dashboard");

                } else {

                    $mdDialog.show( $mdDialog.alert().title('Username / password is incorrect').textContent(response.message)
                    .ok('Got it!'));

                }
            });         

        }

    };



})();

1 个答案:

答案 0 :(得分:0)

我的知识非常有限,但我设法通过在我的登录功能中设置一个单独的功能并从我的其他地方调用它。

function showAlert() {

    var alert;
    alert = $mdDialog.alert()
    .title('Attention,')
    .content('Incorrect username or password; please try agian!')
    .ok('Close');



    $mdDialog.show( alert )
    .finally(function() { 
       alert = undefined;
    });
}