我用的是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的链接

推荐答案

您需要在angularCompilersOptions中启用这些块类型

{
 "angularCompilersOptions": {
  ....
  "_enabledBlockTypes": ["if","for","switch","defer"]
 }
}

Angular相关问答推荐

无法绑定到ngIf,因为它不是dis angular 17的已知属性

RXJS运算符用于combineLatest,不含空值

将Angular 17中的http服务与独立组件一起使用

使用当前选定的选项创建IF语句

以17角表示的自定义元素

Angular -移位在2个示波器中读取

截获火灾前调用公共接口

类是一个独立的组件,不能在Angular中的`@NgModule.bootstrap`数组中使用

如何使用Angular 将图像作为二进制数据发送到我的API?

用于 React 的 ngx-extended-pdf-viewer

SignalR:协商有效,但消息未发送(.NET/Angular)

区分material 手风琴

BehaviorSubject 在 Angular 中制作数据之间的时间表(或计时器)

将 html ngModel 值传递给服务 --Angular

CORS 策略和 .NET Core 3.1 的问题

缺少 .angular-cli.json 文件:Angular

无法获得 angular-material md-sidenav 的 100% 高度

在 Angular 2 中对 observable 进行单元测试

路由 getCurrentNavigation 始终返回 null

ngIf - 判断后表达式已更改