[英]how to conditionally display the innerHTML values using pipe
I am using angular 8. Wanted to conditionally implement the innerHTML using pipe translate.我正在使用 angular 8。想要使用管道翻译有条件地实现innerHTML 。
.html .html
<button type="button"
mat-flat-button
// using translate module internally
[innerHTML] = "display ? (HIDE_NUMBER' : SHOW_NUMBER) | translate)"
(click)="toggle()">
</button>
.ts .ts
//all imports are done
export class New implements OnInit {
public display: boolean;
constructor() {}
toggle() {
this.display = !this.display;
}
}
You have a strange '
after HIDE_NUMBER
:) .你有一个奇怪的
'
在HIDE_NUMBER
:) 之后。 But that's not the only problem但这不是唯一的问题
You need to do something like this你需要做这样的事情
[innerHTML] = " (condition ? 'translate_string'
: 'the_other_translate_string'
) | translate
"
The idea is to wrap the condition inside ()
and then translate the result
from that condition.这个想法是将条件包装在
()
,然后从该条件转换result
。 That's why the translate
pipe is outside the ()
这就是为什么
translate
管道在()
之外
Try like this:像这样尝试:
<button type="button"
mat-flat-button
[innerHTML] = "(display ? 'HIDE_NUMBER' : 'SHOW_NUMBER') | translate"
(click)="toggle()">
</button>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.