Angular NG5002错误无效的ICU消息和意外的字符EOF

标签 angular

我正在使用最新版本的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/

相关文章:

html - Angular 2 : Floating button not floating CSS

javascript - 2个选择选项和默认值的 Angular 问题

javascript - Angular 4 + ng2-datetime jQuery 问题

Angular 没有剪贴板的提供者

angular - Nginx路由到 Angular ssr构建中具有多个根的多个位置

Angular 2 访问基础 href

javascript - 如何从angular2中输入的文本动态设置超链接并使其可通过url点击?

javascript - 需要在执行函数时声明 aria 标签

Angular2-jwt - AuthHttp,刷新 token ,将它们放在一起

javascript - Angular 4 需要导入 Promise