gpt4 book ai didi

javascript - 无法使用 $mdToast 读取未定义的属性 'show'

转载 作者:行者123 更新时间:2023-12-01 03:08:30 24 4
gpt4 key购买 nike

我真的很苦恼这个问题,我不知道出了什么问题......

我将省略很多代码,但这本质上是它的要点...基于 Angular material design guidelines应该可以工作。我一生都无法弄清楚为什么它不会。

当我运行代码时,我只是收到一个错误:类型错误:无法读取未定义的属性“show”

index.html:

<!DOCTYPE html>
<html lang="en" ng-app="Main">
<!-- some stuff here -->
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/angular_material/1.1.0-rc4/angular-material.min.css">
</head>

<body ng-controller="MainCtrl as ctrl">
<div ng-click="executeToast()">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.3/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.3/angular-animate.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular-route.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.3/angular-aria.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.3/angular-messages.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.3/angular-sanitize.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angular_material/1.1.0-rc4/angular-material.min.js"></script>
</body>
</html>

Controller :

angular.module('MainController', [
'MainService',
'MainDirective',
'ngMaterial',
'ngMessages',
'ngSanitize'
])
.controller('MainCtrl', [ '$scope', '$sce', '$mdToast', function($scope, Main, $sce, $apply, $rootScope, $mdToast) {
$scope.executeToast() = function() {
$mdToast.show($mdToast.simple({
hideDelay: 3000,
position: 'top left',
content: 'testing',
toastClass: 'success'
}));
}
}]);

有什么想法或可能的解决方案吗?谢谢!

最佳答案

您在这里犯的几个错误:

1、依赖注入(inject)顺序必须相同,查看更多here

2、无需传递$apply作为依赖项,

试试这个

 .controller('MainCtrl', [ '$scope', '$rootScope', '$mdToast','$sce', function($scope, $rootScope, $mdToast, $sce) {
$scope.executeToast() = function() {
$mdToast.show($mdToast.simple({
hideDelay: 3000,
position: 'top left',
content: 'testing',
toastClass: 'success'
}));

关于javascript - 无法使用 $mdToast 读取未定义的属性 'show',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46009821/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com