我在AngularJS中有一个静态下拉列表,希望它与Firebase一起动态

时间:2017-10-02 15:21:22

标签: angularjs typescript firebase-realtime-database ionic2 phonegap

我有一个离子,打字稿,AngularJS,Pohnegap开发的应用程序。我的一个功能是收集男性或女性的信息 - 我已经制作了这种静态形式

<ion-item>
<ion-label>Brand</ion-label>
  <ion-select interface="popover">
    <ion-option value="heineken">Heineken</ion-option>
    <ion-option value="carlsberg">Carlsberg</ion-option>
  </ion-select>
</ion-item>

这样可以选择女性或男性,我喜欢通过提取数据从Firebase中选择来实现动态。

所以我在我的html文件

中这样做了
<ion-item>
  <ion-label stacked>Type of Trash</ion-label>
      <ion-select [(ngModel)]="BrandsList (ionChange)="onSelectChange($event)">
       <ion-option value="typeofbrand" *ngFor="let title of BrandsList"> {{title}}
      </ion-option>  
      </ion-select>
</ion-item>

在我的.ts文件中,我添加了这个

    BrandsList: FirebaseListObservable<any>;
    ...
    this.BrandsList = db.list('/brands/');

我无法让动态部分发挥作用,任何想法我都做错了。

请参阅下面的firebase数据库中的图片。

enter image description here

感谢任何帮助,我能得到。

1 个答案:

答案 0 :(得分:0)

我认为你应该改变这一部分:

<ion-item>
  <ion-label stacked>Type of Trash</ion-label>
      <ion-select [(ngModel)]="BrandsList (ionChange)="onSelectChange($event)">
       <ion-option value="typeofbrand" *ngFor="let title of BrandsList"> {{title}}
      </ion-option>  
      </ion-select>
</ion-item>

到另一个:

<ion-item>
  <ion-label stacked>Type of Trash</ion-label>
      <ion-select [(ngModel)]="BrandsList (ionChange)="onSelectChange($event)">
       <ion-option value="typeofbrand" *ngFor="let brand of BrandsList"> {{brand.title}}
      </ion-option>  
      </ion-select>
</ion-item>

因为你必须首先搜索品牌,然后再搜索属性

我希望这对你有用! (: