【发布时间】: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