Ion-segment default active 但值是数据绑定到 firebase {{cate.id}} helpppp 请
Ion-segment default active but the value is data binded to firebase {{cate.id}} helpppp please
我正在尝试显示绑定到我的 firebase 的段中的第一个选项卡,我已经尝试执行顶部栏:string = ""; ??????但是我的值是未定义的,因为数据绑定了我真的不知道我该怎么做才能在用户打开页面时默认启用我的段。这是我的代码:`
<ion-segment [(ngModel)]="topbar">
<div *ngFor="let cate of categories">
<ion-segment-button value="{{cate.id}}" [id]="cate.id" >
{{cate.name}}
</ion-segment-button>
</div>
</ion-segment>
</ion-toolbar>`
这是 ts(我知道它错了:( ):
topbar: string = "{{cate.id}}";
试试这个。
在html
<ion-segment scrollable value="{{firstId}}" (ionChange)="segmentChanged($event)">
<ion-segment-button *ngFor="let cate of categories" value="{{cate.id}}" id="{{cate.id}}" >
<ion-label>{{cate.name}}</ion-label>
</ion-segment-button>
</ion-segment>
您需要将 firstId 提供给 ts 文件中的第一个类别 id。
在 ts
firstId: any;
getDataFromServer()
{
//your code to get data
//after add this
this.firstId = category[0].id;
}
我正在尝试显示绑定到我的 firebase 的段中的第一个选项卡,我已经尝试执行顶部栏:string = ""; ??????但是我的值是未定义的,因为数据绑定了我真的不知道我该怎么做才能在用户打开页面时默认启用我的段。这是我的代码:`
<ion-segment [(ngModel)]="topbar">
<div *ngFor="let cate of categories">
<ion-segment-button value="{{cate.id}}" [id]="cate.id" >
{{cate.name}}
</ion-segment-button>
</div>
</ion-segment>
</ion-toolbar>`
这是 ts(我知道它错了:( ):
topbar: string = "{{cate.id}}";
试试这个。
在html
<ion-segment scrollable value="{{firstId}}" (ionChange)="segmentChanged($event)">
<ion-segment-button *ngFor="let cate of categories" value="{{cate.id}}" id="{{cate.id}}" >
<ion-label>{{cate.name}}</ion-label>
</ion-segment-button>
</ion-segment>
您需要将 firstId 提供给 ts 文件中的第一个类别 id。
在 ts
firstId: any;
getDataFromServer()
{
//your code to get data
//after add this
this.firstId = category[0].id;
}