简体   繁体   English

在 (#loading) ng-template 中时,ion-progress-bar 显示不正确

[英]ion-progress-bar doesn't show correctly when inside a (#loading) ng-template

this is my first question.这是我的第一个问题。 I've done a #loading template with an ion progress bar inside, but it doesn't show on the footer of the page (nor in the header if i try it too).我做了一个 #loading 模板,里面有一个离子进度条,但它没有显示在页面的页脚上(如果我也尝试的话,也不会显示在 header 中)。 It shows next to header.它显示在 header 旁边。

<ng-container *ngIf="getLibraryService.getLibraryItem$ | async;else loading; let items"> 
// code
<\ng-container>
<ng-template #loading>
  <footer><ion-progress-bar type="indeterminate"></ion-progress-bar></footer>
</ng-template>

Later I tried something to avoid this ng-template, doing a variable isLoadingActive and a function to isLoading(b: boolean).后来我尝试了一些方法来避免这个 ng-template,做一个变量 isLoadingActive 和一个 function 到 isLoading(b: boolean)。 But i cannot get it to work more than once:但我不能让它工作不止一次:

<ng-container *ngIf="getLibraryService.getLibraryItem$ | async; else loadingCaller; let items">   
  {{ showLoading(false)}}
  <ng-container *ngIf="items?.length > 0; else emptyLibrary">
     // code
  <\ng-container>
<\ng-container>

<ng-template #loadingCaller>1{{showLoading(true)}}</ng-template>
<footer>
  <ion-progress-bar *ngIf="isLoadingActive" type="indeterminate"></ion-progress-bar>
</footer>

I have put an {{ isLoadingActive }} in the.html to track the value, and it seems it doesn't change when the Observer<libraryItem[]> sends new values that i have filtered in my functions.我在 .html 中放置了一个 {{ isLoadingActive }} 来跟踪该值,当 Observer<libraryItem[]> 发送我在我的函数中过滤的新值时,它似乎没有改变。 Or if i put a {{showLoading(false) }} in my emptyLibrary template and i do an empty search with the ion-search-bar.或者,如果我将 {{showLoading(false) }} 放入我的 emptyLibrary 模板中,然后使用 ion-search-bar 进行空搜索。

I can change the ion-progress-bar to another thing i supose, but not knowing why my {{showLoading(false)}} doesn't trigger the second time the page refreshes (when i click to a filter button or do a research) annoys me a lot.我可以将 ion-progress-bar 更改为我想的另一个东西,但不知道为什么我的 {{showLoading(false)}} 没有触发第二次页面刷新(当我点击过滤器按钮或进行研究时) 很烦我。

Finally I got the solution for the problem in this stack overflow question: How to get nativeElement from @ViewChild in Ionic 4/Angular7?最后我得到了这个堆栈溢出问题的解决方案: How to get nativeElement from @ViewChild in Ionic 4/Angular7?

Creating a ion-progress-bar in the html and getting the child in the.ts modifying the properties programatically.在 html 中创建一个 ion-progress-bar 并让孩子在 .ts 中以编程方式修改属性。

<footer>
  <ion-progress-bar color="secondary" type="indeterminate" #ionPB></ion-progress-bar>
</footer>
// VARIABLES
@ViewChild('ionPB') elemPB: IonProgressBar;

showLoading(bShow: boolean) {
  if (!bShow) {
    this.elemPB.type = 'determinate';
    this.elemPB.value = 0;
    return;
  }

There where another possible answers to change the view that i couldnt manage to get done (ngZone, changeDetectorRef, subjectBehavior, ...).那里有另一个可能的答案来改变我无法完成的视图(ngZone,changeDetectorRef,subjectBehavior,...)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM