html - Angular:将函数从常量绑定到html
问题描述
在 Angular 中,我将一些模板定义为常量,模板渲染得很好,但我想将事件附加到 html 常量中的元素。我似乎无法像在@Component 定义中定义模板时那样绑定函数。
这是一段描述我尝试过的代码。
export class SomeComponent implements OnInit {
public ngOnInit(): void {
const someHtml = `
<a (click)="someFunction()" href="someUrl">link</a>
`
.. some code that uses the const
}
public someFunction() {
console.log("clicked")
}
}
我该怎么办?
解决方案
推荐阅读
- javascript - Tampermonkey,根据行数单击按钮 x 次
- html - 如何使网站内容在右侧边栏之后?
- amazon-web-services - Flask - SQLite3 部署
- reactjs - 如何更改我也作为道具收到的组件的道具?
- java - Java Selenium 错误:NoClassDefFoundError:org/openqa/selenium/HasAuthentication
- java - 设备主题模式确实会阻止应用主题模式。安卓工作室 Java
- google-apps-script - 在 Google 表格的不同列上检查最大值和最小值
- sql-server - 在权限链的情况下拒绝不优先?
- r - X轴为年月的ggplot
- java - 如何防止测试中违反参照完整性约束?