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

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

可觀察訂閱觸發(fā)后未更新的角度 UI

可觀察訂閱觸發(fā)后未更新的角度 UI

慕蓋茨4494581 2022-08-04 17:59:08
我有一個(gè)角度頁(yè)面,它使用來(lái)自服務(wù)的可觀察參數(shù)。但是,當(dāng)此可觀察更新時(shí),頁(yè)面不會(huì)更新以匹配。我嘗試過(guò)將可觀察的結(jié)果存儲(chǔ)在平面值中,或者更改布爾值以調(diào)整UI,但似乎沒(méi)有效果。記錄可觀察對(duì)象可確認(rèn)它已正確更新,并在重新導(dǎo)航到該頁(yè)面時(shí)顯示新值。其他條件 UI 更新可以正確修改頁(yè)面,只有下面的一個(gè) () 導(dǎo)致此問(wèn)題。*ngIf="(entries$ | async), else loading"component.tsexport class EncyclopediaHomeComponent implements OnInit {  entries$: Observable<EncyclopediaEntry[]>;  categories$: Observable<string[]>;  entry$: Observable<EncyclopediaEntry>;  entry: EncyclopediaEntry;  isEditing: boolean;  constructor(private route: ActivatedRoute, private encyService: EncyclopediaService) {    this.entries$ = encyService.entries$;    this.categories$ = encyService.categories$;    this.entries$.subscribe(es => {      console.log(es);    });    route.url.subscribe(url => this.isEditing = url.some(x => x.path == 'edit'));    this.entry$ = route.params.pipe(      switchMap(pars => pars.id ? encyService.getEntry(pars.id) : of(null)),    );    this.entry$.subscribe(entry => this.entry = entry);  }  ngOnInit(): void {  }  updateEntry(entry: EncyclopediaEntry) {    this.encyService.updateEntry(entry.id, entry);  }}組件.html<div class="encyclopedia-container">    <ng-container *ngIf="(entries$ | async), else loading">        <app-enc-list [entries]="entries$ | async"            [selectedId]="entry ? entry.id : null"></app-enc-list>        <ng-container *ngIf="entry">            <app-enc-info *ngIf="!isEditing, else editTemplate"                [entry]="entry$ | async"></app-enc-info>            <ng-template #editTemplate>                <app-enc-edit [entry]="entry$ | async" [categories]="categories$ | async"                    (save)="updateEntry($event)"></app-enc-edit>            </ng-template>        </ng-container>    </ng-container>    <ng-template #loading>        <mat-progress-bar mode="indeterminate"></mat-progress-bar>        <br>        <p>Loading Encyclopedia...</p>    </ng-template></div>
查看完整描述

1 回答

?
絕地?zé)o雙

TA貢獻(xiàn)1946條經(jīng)驗(yàn) 獲得超4個(gè)贊

該組件似乎沒(méi)有看到更改。我不知道為什么,因?yàn)閨異步將完成這項(xiàng)工作。


但要修復(fù)它,您可以使用ChangeDetector:



constructor(

   private route: ActivatedRoute,  

   private encyService: EncyclopediaService

   private changeDetectorRef: ChangeDetectorRef,

) {

    this.entries$ = encyService.entries$;

    this.categories$ = encyService.categories$;


    this.entries$.subscribe(es => {

      // setTimeout need to run without troubles with ng changes detector

      setTimeout(_=>{this.changeDetectorRef.detectChanges()},0);

      ...

    });

或者你可以使用markforCheck,就像那里描述的那樣。


查看完整回答
反對(duì) 回復(fù) 2022-08-04
  • 1 回答
  • 0 關(guān)注
  • 154 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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