我有一个问题,在我的表单上,我有一个嵌套控制器,而子控制器是一个模态控制器,其中包含一些输入字段。现在我的问题是我想在关闭模态后传递表单数据。我尝试使用resolve,但是我不知道该返回什么。这是我的代码:
ParentController
question = {}
openAddEditCoursewareModal(mode, id, data, actionType) {
let ctrl = this;
if(ctrl.QuestionsStore.questionnaireType == 'Questionnaire') {
//this.questionType = 'Questionnaire';
var modalInstance = ctrl.$modal.open({
template: '<addeditcourseware-modal modal-options="$ctrl.modalOptions" close="$ctrl.close()"></addeditcourseware-modal>',
controller: ['$modalInstance', function($modalInstance, items) {
this.modalOptions = {
mode: mode,
id: id,
data: angular.copy(data),
actionType: mode //set to mode temporarily should be ActionType
}
this.close = $modalInstance.close;
this.childData = {};
}],
size: 'small',
controllerAs: '$ctrl',
resolve: {
items: function() {
console.log('here here');
}
},
windowClass: 'addeditcourseware-modal'
});
modalInstance.result.then(function(result) {
try {
} catch(e) {
console.log('Error!');
}
});
} else {
// some code
}
}
子级或嵌套控制器
submitForm() {
console.log('Action Type: ', this.modalOptions.actionType);
if (this.modalOptions.actionType === 'add' || this.modalOptions.actionType === 'duplicate'){
console.log("Form Data: ", angular.toJson(this.question)); // NO PROBLEM HERE. IT SHOWS MY FORM DATA
this.close(this.question);
} else if (this.modalOptions.actionType === 'edit') {
this.updateQuestion(formData);
}
}
// Close modal
close(formData) {
this.modalInstance.close(formData);
}
我的父模板的一部分:(无数据显示)
<pre>
Test:
{{ $ctrl.question }}
</pre>
仅此而已,希望您能为我提供帮助。谢谢。