【发布时间】:2019-03-13 20:55:41
【问题描述】:
我想展示一个带有角度材质库的滑块。 这里的目标是,当我滑动以选择订阅的用户数量时,价格会在我向后或向前滑动时动态变化。
我可以在我的 ts 组件中设置值,但它不会在 html 中动态更改,但我做了双绑定括号 {{}}。我有点困惑为什么它不起作用。
subscriptioncomponent.html
<h1>Subscription</h1>
<h5>Choose how much user your account will have</h5>
<h5> {{amount}} Euro/month</h5>
<h5>{{user}} Users</h5>
<mat-slider
thumbLabel
[displayWith]="formatLabel"
tickInterval="auto"
min="1"
max="10"
[(ngModel)]="value"></mat-slider>
subscriptioncomponent.ts
export class SubscriptionchooseComponent implements OnInit {
amount : number = 0;
user : number = 0;
value: number = 1;
formatLabel(value: number | null) {
if (!value) {
return 0;
}
this.value = value;
console.log(this.value);
return value;
}
constructor() {
this.user = this.value;
this.amount = this.user * 9;
console.log(this.amount);
console.log(this.value);
}
ngOnInit() {
}
}
【问题讨论】:
-
让我们也试试我的答案。它的工作完美测试,而且你在 html 和 ts 方面都有价值。您可以进一步使用..
-
嗨,我试过了。它有效,但我检查的解决方案更简单并且可以满足我的需要。但也感谢您的解决方案
标签: angular typescript slider angular-material