吐司显示错误

时间:2016-05-02 15:18:57

标签: angularjs

我想在我的应用中显示吐司。为此我用过:

mySchoolApp.controller('loginController', ['$scope', '$http', function($scope, $http,$location, $mdToast) {
this.loginForm = function() {

        let uname = this.inputData.username;
        let pass= this.inputData.password;
            if (pass === 123456) {
                sessionStorage.setItem("userID", '123456');
                window.location.href = '#dashboard';

            } else {
                $mdToast.show(
  $mdToast.simple()
    .textContent('Either email or password is incorrect!')
    .position("top right")
    .hideDelay(3000)
);

            }
        })
        .error(function(data, status, headers, config) {
            //error msgs
        })
    }
}]);

但在运行我的应用时,它显示以下错误:

  

TypeError:无法读取未定义

的属性'show'

如何在我的应用中对此问题进行排序?

1 个答案:

答案 0 :(得分:1)

你错过了控制器的依赖注入数组中的toast服务:

mySchoolApp.controller('loginController', ['$scope', '$http', '$location', '$mdToast', function($scope, $http,$location, $mdToast) ......