[英]Angular *ngIf <mat-slide-toggle >
how to open the <mat-slide-toggle>
if the currentFight is in bet-open and on-going and how to close the <mat-slide-toggle>
if the currentFight is in on-standby
and last-call
?如果currentFight处于下注状态且正在进行中,如何打开<mat-slide-toggle>
<mat-slide-toggle>
以及如果currentFight处于on-standby
和last-call
状态,如何关闭 <mat-slide-toggle> ?
<label class="mb-10 mr-15">Close </label>
<mat-slide-toggle [checked]="isSlideChecked"></mat-slide-toggle>
<label class="mb-10 ml-15">Open </label>
this is my type script这是我的打字稿
import { Component, OnInit, Input } from '@angular/core';
import { MatSlideToggleChange } from '@angular/material/slide-toggle';
@Component({
selector: 'app-odds-editor',
templateUrl: './odds-editor.component.html',
styleUrls: ['./odds-editor.component.scss']
})
export class OddsEditorComponent implements OnInit {
@Input() currentFight: any;
constructor() { }
public isSlideChecked: boolean = false;
ngOnInit() {
}
toggleChanges($event: MatSlideToggleChange) {
if(this.currentFight){
if(this.currentFight == 'on-standby'){
this.isSlideChecked = $event.checked;
}
else if(this.currentFight == 'bet-open'){
this.isSlideChecked = $event.checked;
}
else if(this.currentFight == 'last-call'){
this.isSlideChecked = $event.checked;
}
else if(this.currentFight == 'on-going'){
this.isSlideChecked = $event.checked;
}
// if currentFight
// this.isSlideChecked = $event.checked;
}
}
}
<mat-slide-toggle>
should have a [checked]
input property that you can bind to. <mat-slide-toggle>
应该有一个可以绑定的[checked]
输入属性。
This should show the toggle as selected.这应该将切换显示为选中状态。
<mat-slide-toggle [checked]="true"></mat-slide-toggle>
This should show the toggle as not selected.这应该将切换显示为未选中。
<mat-slide-toggle [checked]="false"></mat-slide-toggle>
You can replace value of the [checked]
property with a variable from your component if you need to be able to select/de-select the slider from your code.如果您需要能够从代码中选择/取消选择 slider,则可以将[checked]
属性的值替换为组件中的变量。
The official documentation: https://material.angular.io/components/slide-toggle/examples官方文档: https://material.angular.io/components/slide-toggle/examples
Updated:更新:
Try changing your html to尝试将您的 html 更改为
<label class="mb-10 mr-15">Close </label>
<mat-slide-toggle [checked]="isSlideChecked()"></mat-slide-toggle>
<label class="mb-10 ml-15">Open </label>
and your ts to和你的 ts
import { Component, OnInit, Input } from '@angular/core';
@Component({
selector: 'app-odds-editor',
templateUrl: './odds-editor.component.html',
styleUrls: ['./odds-editor.component.scss']
})
export class OddsEditorComponent implements OnInit {
@Input() currentFight: any;
constructor() { }
ngOnInit() {
}
isSlideChecked() {
if(this.currentFight == 'on-standby' || this.currentFight == 'bet-open'){
return true;
}
return false;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.