【发布时间】:2017-08-17 23:05:35
【问题描述】:
我不知道为什么,但我在隐藏/取消时收到 unhandled rejection AngularJS 材料 mdDialog 错误
mdDialog 的代码:
$scope.addAttendee = function(ev) {
$mdDialog.show({
controller: DialogController,
templateUrl: 'views/regForm.tmpl.html',
parent: angular.element(document.body),
targetEvent: ev,
clickOutsideToClose:true,
controllerAs: 'ctrl',
fullscreen: $scope.customFullscreen, // Only for -xs, -sm breakpoints.
locals: {parent: $scope}
})
.then(function(response){
if(angular.isDefined(response)){
attendees.push(response);
}
console.log(attendees);
console.log(attendees.length);
})
当我删除一个承诺时,对话框可以关闭而没有错误消息。
有什么线索吗?
【问题讨论】:
-
'未处理的拒绝'意味着一个承诺被拒绝但错误没有得到处理。添加
.catch以找出错误所在,并在每次有可能拒绝承诺时执行此操作。 -
尝试像这样添加拒绝功能:
.then(function(response){}, function(reject){ //console.log(reject)})来解决错误。 -
我看到 mdDialog 仍然让你有些头疼,哈哈。问候。老兄@JackTheKnife
-
$mdDialog.cancel() 返回一个被拒绝的承诺是正常的
-
如果$mgDialog.hide() 收到未处理的拒绝,则很可能
.then块中的代码引发了错误。可能变量attendees不是数组,因此Uncaught TypeError: Cannot read property 'push'。在.then块之后添加.catch块以查看错误。
标签: angularjs angularjs-material