【问题标题】:Ion-segment default active but the value is data binded to firebase {{cate.id}} helpppp please离子段默认激活,但值是绑定到 firebase {{cate.id}} helpppp 的数据
【发布时间】:2020-11-16 00:28:51
【问题描述】:

我正在尝试显示绑定到我的 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 angular typescript ionic-framework ionic3


    【解决方案1】:

    试试这个。

    在 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;
    }
    

    【讨论】:

    • 感谢这按预期工作!!!!!!你拯救了我的一天。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-04-16
    • 1970-01-01
    • 2013-11-17
    • 2017-08-10
    • 1970-01-01
    • 2012-05-21
    • 2016-10-07
    相关资源
    最近更新 更多