【问题标题】:value doesn't bind to selector at angular 6值不会在角度 6 处绑定到选择器
【发布时间】:2020-10-26 04:20:01
【问题描述】:

绑定失败@ angular 6

export class UserListComponent implements OnInit {

  title = 'Tour of Heroes';

}

<sa-big-breadcrumbs [items]="['Category', '{{title}}' ]" class="classbig"></sa-big-breadcrumbs>

大面包屑.component.ts

  selector: 'sa-big-breadcrumbs',
  template: `
    <div class="row">
      <h4 class="header">
        <i class="fa-{{icon}}"></i> {{items[0]}} <span *ngFor="let item of items.slice(1)"> > {{item}}</span>
      </h4>
    </div>
  `,

抛出错误, 未捕获(承诺中):错误:模板解析错误....

我需要替换它,以便它可以放入正确的 html 格式,以便翻译进行翻译 例如下面:

<div class="row">
  <h4 class="header">
    <i class="fa-{{icon}}"></i> {{items[0]}} <span *ngFor="let item of items.slice(1)"> > {{item}}</span>
  </h4>
</div>

替换为

<div class="row">
  <h4 class="header">
    <i class="fa-{{icon}}"></i> {{items[0]}} <span *ngFor="let item of items.slice(1)"> >  {{ 'item' | translate }}</span>
  </h4>
</div>

这样最终的 html 就可以出来了

类别 > 英雄之旅(普通) 类别>英雄之旅(通过库检测翻译)

有什么方法可以将值从 ts 绑定到 html?

【问题讨论】:

  • 乍一看,它看起来不错。请提供您的组件的代码
  • 字符串插值大括号在 js 表达式中无效。将[items]="['Category', '{{title}}' ]" 替换为[items]="['Category', title]"

标签: angular data-binding binding


【解决方案1】:

格式不正确:

[items]="['Category', '{{title}}' ]"

应该是这样的:

[items]="['Category', title ]" 

【讨论】:

    【解决方案2】:

    字符串插值大括号在 js 表达式中无效。将[items]="['Category', '{{title}}' ]" 替换为[items]="['Category', title]"

    【讨论】:

      【解决方案3】:

      首先你需要替换下面的代码。

      [items]="['Category', '{{title}}' ]"

      [items]="['Category', title ]"

      除了更改为....

      <div class="row">
        <h4 class="header">
          <i class="fa-{{icon}}"></i> {{items[0] | translate}} <span *ngFor="let item of items.slice(1)"> >  {{ 'item[0]' | translate }}</span>
        </h4>
      </div>

      【讨论】:

        猜你喜欢
        • 2019-04-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-05-16
        • 2014-10-19
        • 1970-01-01
        相关资源
        最近更新 更多