我正在使用最新版本的Angular 17.0.0-next.6这增加了对新控制流的支持,我看到 Twitter 上的人说这对他们来说工作得很好,所以这一定是我的问题
我在新项目中按预期使用所有内容,并用此代码替换 app.component.html
@if(title) {
title
} @else {
no title
}
但它给了我以下错误
X [ERROR] NG5002: Invalid ICU message. Missing '}'. [plugin angular-compiler]
src/app/app.component.html:6:0:
6 │
╵ ^
Error occurs in the template of component AppComponent.
src/app/app.component.ts:9:15:
9 │ templateUrl: './app.component.html',
╵ ~~~~~~~~~~~~~~~~~~~~~~
X [ERROR] NG5002: Unexpected character "EOF" (Do you have an unescaped "{" in your template? Use "{{ '{' }}") to escape it.) [plugin angular-compiler]
src/app/app.component.html:6:0:
6 │
╵ ^
Error occurs in the template of component AppComponent.
src/app/app.component.ts:9:15:
9 │ templateUrl: './app.component.html',
╵ ~~~~~~~~~~~~~~~~~~~~~~
链接 stackblitz
最佳答案
您需要在 tsconfig.json
的 angularCompilersOptions 中启用这些 block 类型
{
"angularCompilersOptions": {
....
"_enabledBlockTypes": ["if","for","switch","defer"]
}
}
关于Angular NG5002错误无效的ICU消息和意外的字符EOF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/77204955/