使用 Aurelia,您可以将东西放入容器中,然后注入。容器状态不在对话框中共享。
有没有办法获取我在容器中注入的数据,并在对话框中使用它?
代码示例
主页.js
fetchString(){
this.data = JSON.parse(stringform);
this.container.registerInstance('tpscform', this.data);
}
自定义元素.js
import {DialogService} from 'aurelia-dialog';
import {LookupFieldsDialog} from './dialog/lookup-fields-dialog';
@inject('tpscform', DialogService)
export class LookupFieldsQuestion {
constructor(form, dialog){
console.log(form); // returns the object from the container - works
//...
}
submit() {
this.dialogService.open({
viewModel: LookupFieldsDialog,
model: this.question,
lock: false
});
}
}
查找字段-dialog.js
import {inject} from 'aurelia-framework';
import {DialogController} from 'aurelia-dialog';
@inject(DialogController, 'tpscform')
export class LookupFieldsDialog {
constructor(controller, form) {
this.controller = controller;
console.log(form); // Returns the string 'tpscform' - doesn't work
}
activate(question) {
this.question = question;
}
}