Javascript 如何在角度模式关闭后返回更改或将值返回给父级
代码如下: parent.ts parent.html 我在这里尝试做的是在提交之后,模式将被关闭,然后如果addName的值为true,那么值addArea将更改为false 因为我在尝试保存/提交时遇到问题,当我尝试将addArea的值更改为true时,该值仍然为true 我也试着这样做: parent.htmlJavascript 如何在角度模式关闭后返回更改或将值返回给父级,javascript,angular,typescript,Javascript,Angular,Typescript,代码如下: parent.ts parent.html 我在这里尝试做的是在提交之后,模式将被关闭,然后如果addName的值为true,那么值addArea将更改为false 因为我在尝试保存/提交时遇到问题,当我尝试将addArea的值更改为true时,该值仍然为true 我也试着这样做: parent.html child.ts @Input()addName:boolean; @输出() addNameChange=新的EventEmitter(); @Input()addName:
child.ts
@Input()addName:boolean;
@输出()
addNameChange=新的EventEmitter();
@Input()addName:boolean;
编辑布局(车间?:任何,行?:任何){
this.modalRef=this.modal.create({
......
.....
.....
.......
.......
});
this.modal.afterAllClose.subscribe((x:any)=>{
this.addNameChange.emit(!this.addName);
});
}
但是它仍然不起作用。除了已经尝试过的内容(添加事件发射器和在模态完成时发射,并准备好告诉父组件要做什么)之外,您还必须在子组件发射时告诉父组件做些什么,将以下内容添加到父html模板中:
<app-child [addNewName]="addName" (addNameChange)="resetNameChange($event)"></app-child>
在ngOnInit(){…}上查找事件发射器。它仍然为true,没有更改。如果值正在更改,则在尝试控制台时是否需要将其移动到ngOnChange(){..}。
<div class="modal-body">
<label class="pb-2">Name</label>
<input nz-input class="mr-2" [(ngModel)]="newInputName" placeholder="Type name...">
</div>
<nz-divider></nz-divider>
<section class="form-footer" nz-row>
<div nz-col>
<button class="mr-1" nz-button nzType="primary" type="button" (click)="addItem()"
[disabled]="newInputName.length <= 0">Add Name</button>
<button nz-button class="btn-secondary" type="button" (click)="modalRef.close()"
[textContent]="'Cancel' | translate"></button>
</div>
</section>
@Input() addName: boolean;
editLayout(shopFloor?: any, lines?: any) {
this.modalRef = this.modal.create({
......
.....
.....
.......
.......
});
this.modal.afterAllClose.subscribe((x: any) => {
this.addName = false;
});
}
<app-child [addNewName]="addName"></app-child>
@Input() addName: boolean;
@Output()
addNameChange = new EventEmitter<boolean>();
@Input() addName: boolean;
editLayout(shopFloor?: any, lines?: any) {
this.modalRef = this.modal.create({
......
.....
.....
.......
.......
});
this.modal.afterAllClose.subscribe((x: any) => {
this.addNameChange.emit(!this.addName);
});
}
<app-child [addNewName]="addName" (addNameChange)="resetNameChange($event)"></app-child>
...
resetNameChange(val) {
...do logic here, probably this.addName = val;
}