【发布时间】:2021-04-28 04:11:46
【问题描述】:
在我的 Angular 应用程序中,如果我通过 url 事件发射器发出的事件未在父组件中触发。
例如:
如果我在浏览器中输入完整的网址。 http://localhost:4200/child
我的子组件正在加载。但是关闭事件发射器发出的事件未在父组件中触发。下面是我的代码。
文件:app.routing.module.ts
const routes: Routes = [
{path : 'child', component : ChildComponent},
];
文件:app.component.html
<div>
<app-bibdpayment *ngIf="show == true" (close)="cancel()"></app-bibdpayment>
<router-outlet></router-outlet>
文件:app.component.ts
cancel() {
this.show = false;
}
文件:childcomponent.html
<button class="btn btn-primary" (click)="cancel()">Cancel</button>
文件:childcomponent.ts
@Output() close = new EventEmitter<void>();
cancel() {
this.close.emit();
}
为什么事件发射器不工作。当我们直接调用子组件url时。
如何解决此问题。任何帮助将不胜感激!!!
【问题讨论】:
-
(close)="cancel($event)和this.close.emit(1)尝试使用此更新并在控制台中检查您是否收到事件?