如何解决Angular:有没有一种方法可以直接在模板中使用可观察的东西?
有没有一种方法可以直接消耗模板中可观察对象发出的值。
我想做的是消耗可观察的值并从中构造一个字符串。
例如
[style]="width: {progress$ | async}%"
我尝试这样做
<div class="progress">
<div
class="progress-bar"
role="progressbar"
[style]="width: {{progress | async}}%;"
aria-valuenow="25"
aria-valuemin="0"
aria-valuemax="100"
></div>
</div>
但是我不断收到错误消息
Failed to compile.
Error: Quotes are not supported for evaluation!
Statement: {{progress$ | async}}%; located at C:/Aditya/playground/practice/Angular/progress-bar/src/app/progress-bar/progress-bar.component.html@4:13
解决方法
这将起作用
[style.width.%]="progress | async"
这是一个StackBlitz演示
https://stackblitz.com/edit/angular-ivy-9uueyg?file=src%2Fapp%2Fapp.component.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。