第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

數(shù)據(jù)來自API,但不顯示。Angular 9 ABP 框架

數(shù)據(jù)來自API,但不顯示。Angular 9 ABP 框架

慕森王 2023-09-28 16:38:47
我想在放置在標(biāo)頭子組件中的選擇控件中填充數(shù)據(jù),但數(shù)據(jù)來自 API,但不顯示。 ngOnInit() {    this._assingedSiteService.getAssignedSitesForLogInUser().subscribe(      (res) => {        this.sites = res;        console.log(this.sites);      },      (error) => {        console.log(error);      }    );  }<li class="nav-item">  <select class="form-control">    <option *ngFor="let site of sites">      {{site.siteName | json}}    </option>  </select></li>
查看完整描述

1 回答

?
臨摹微笑

TA貢獻(xiàn)1982條經(jīng)驗 獲得超2個贊

在渲染頁面之前需要等待接收到的數(shù)據(jù)。你可以做兩件事:


使用布爾值和ngIf指令:


 loadingData = true;

 ngOnInit() {

     this._assingedSiteService.getAssignedSitesForLogInUser().subscribe((res) => {

         this.sites = res;

         console.log(this.sites);

         this.loadingData = false;

       }, (error) => {

         console.log(error);

       }

     );

 }

模板


   <select class="form-control" *ngIf="!loadingData">

     <option *ngFor="let site of sites">

       {{site.siteName | json}}

     </option>

   </select>

我更喜歡,如果您的訂閱中沒有邏輯,請async在模板中使用管道:


 sites$: Observable<Site>;


 ngOnInit() {

    this.sites$ = this._assingedSiteService.getAssignedSitesForLogInUser();

 }

模板:


   <select class="form-control">

     <option *ngFor="let site of sites$ | async">

       {{site.siteName | json}}

     </option>

   </select>


查看完整回答
反對 回復(fù) 2023-09-28
  • 1 回答
  • 0 關(guān)注
  • 106 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號