我想自动点击ngOnInit()
按钮,在以前的 Angular 版本中它工作正常,但现在它
显示无法读取 null 的属性“click”
这是我的代码 html
<button type="button" id="auto_trigger" (click)="editModal(editcontent,param_asset_ref)" class="btn btn-warning">click</button>
ts 文件
let element:HTMLElement = document.getElementById('auto_trigger') as HTMLElement;
element.click();
最佳答案
这是实现的工作示例,看看 angular-8-auto-trigger-click-event-not-working
在app.component.ts中添加以下代码
ngOnInit(){
let element:HTMLElement = document.getElementById('auto_trigger') as HTMLElement;
// add this condition will solve issue
if(element){
element.click();
}
}
editModal(editcontent,param_asset_ref){
console.log('clicked');
}
app.component.html
<button type="button" id="auto_trigger" (click)="editModal(editcontent,param_asset_ref)" class="btn btn-warning">click</button>
关于javascript - Angular 8自动触发点击事件不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60648452/