嗨我有一个问题,我从 Angular Material 显示一个 mdDialog 并使用我的指令控制器作为对话框的控制器,这样我就可以调用特定的函数,而不必将东西传回并在代码中添加额外的步骤。函数成功调用,但函数成功结束时 UI 未更新。想知道是否有人可以看到我在哪里出错了。
现在假设第一个 if 语句为真。
对话调用
this.showImageUploadModal = function() {
$mdDialog.show({
clickOutsideToClose: true,
scope: $scope, // use parent scope in template
preserveScope: true, // do not forget this if use parent scope
templateUrl: 'app/directives/modals/upload-files-modal.html',
controller: MessagingController,
controllerAs: 'controller'
});
};
函数被调用但不更新 UI
this.addAttachment = function() {
console.log("sending attachment");
var ref = this;
var note = this.user.first_name + " has attached a file.";
if($state.current.name === 'inbox') {
MessagingService.createMessage(this.convo.id, note, this.userUploadedNoteFiles).then(
function success(response) {
console.log("Inbox attachment sent", response);
ref.convo.messages.push(response.data);
console.log(ref.convo.messages);
// ref.viewableNoteFiles = [];
},
function failure(response) {
$mdToast.show(
$mdToast.simple().
textContent("Failed to send the message please try again.").
theme('error-toast'));
}
);
} else if (this.notes === 'true') {
TicketingService.addNote($stateParams.id, note, this.userUploadedNoteFiles).then(
function success(response) {
console.log("Notes attachment sent", response);
ref.convo.messages.push(response.data);
// ref.viewableNoteFiles = [];
},
function failure(response) {
$mdToast.show(
$mdToast.simple().
textContent("Failed to send the message please try again.").
theme('error-toast'));
}
);
} else if(this.contractor === 'true') {
TicketingService.createMessage($stateParams.id, this.convo.id, note, this.userUploadedNoteFiles).then(
function success (response) {
console.log("Contractor attachment sent", response);
ref.convo.messages.push(response.data);
},
function failure () {
$mdToast.show(
$mdToast.simple().
textContent("Failed to upload the file attachments").
theme('error-toast'));
}
);
}
};