[英]Angular 10 tries to parse string as typescript code
When using a string as input from parent to a child component, Angular tries to parse the string as TS code and throws an error.当使用字符串作为从父组件到子组件的输入时,Angular 尝试将字符串解析为 TS 代码并抛出错误。
Example: https://stackblitz.com/edit/angular-10-communicating-between-components-8yqvse?file=src%2Fapp%2Fapp.component.html示例: https : //stackblitz.com/edit/angular-10-communicating-between-components-8yqvse?file=src%2Fapp%2Fapp.component.html
This did not happen in Angular 8: https://stackblitz.com/edit/angular-8-getting-started-ytub1a?file=src%2Fapp%2Fapp.component.html这在 Angular 8 中没有发生: https : //stackblitz.com/edit/angular-8-getting-started-ytub1a? file = src%2Fapp% 2Fapp.component.html
What caused this issue?是什么导致了这个问题? There is no mention of parser change in Angular 10 release note.
Angular 10 发行说明中没有提到解析器的变化。
This happen because string has interpolation inside {{ option }}
.发生这种情况是因为 string 在
{{ option }}
有插值。 Check interpolation docs检查插值文档
So if you assign a variable to option or remove brackets will works.因此,如果您将变量分配给选项或删除括号将起作用。
Working example : https://stackblitz.com/edit/angular-10-communicating-between-components-cugx4n?file=src/app/app.component.ts工作示例: https : //stackblitz.com/edit/angular-10-communicating-between-components-cugx4n?file=src/app/app.component.ts
Edit: Here is the exactly commit that introduce this.编辑:这是介绍这一点的确切提交。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.