【问题标题】:Why *ngIF is not working in Cordova Angular?为什么 *ngIF 在 Cordova Angular 中不起作用?
【发布时间】:2022-01-18 16:39:25
【问题描述】:

我已经被困了一段时间了。确认 this.progressBarValue 更改为 true。但是没有显示进度条。有人可以提前帮助我吗?

一些组件.html

<div class="progressBar">
  <mat-progress-bar class="fileProgress" mode="indeterminate" *ngIf="progressBarValue">
  </mat-progress-bar>
</div>

一些组件.ts

confirmConversion() {
this.progressBarValue = true;
console.log(this.progressBarValue)
var filepath = this.filePath;
var fileextension = this.settingsExtension;
new Promise((resolve, reject) => {
  window.ConvertMedia(filepath, fileextension, resolve, reject);
}).then((message) => {
  console.log(message);
});}

如果我不调用 Cordova API,它正在工作(显示进度条)。
我也尝试过使用下面给出的一些方法,但没有奏效。

this.zone.run(() => this.progressBarValue = true)
  console.log(this.progressBarValue)

this.changeDetector.detectChanges() & this.changeDetector.markForCheck()

注意:如果我在里面更新 this.progressBar = true 会显示 ProgressBar

.then((message) => {console.log(message);});

【问题讨论】:

    标签: android angular cordova cordova-plugins


    【解决方案1】:

    我会尝试将 *ngIf 添加到容器 - div 中:

    <div class="progressBar" *ngIf="progressBarValue">
      <mat-progress-bar class="fileProgress" mode="indeterminate">
      </mat-progress-bar>
    </div>
    

    如果progressBarValue 的默认值为false,则mat-progress-bar 无法正确加载。
    如果它有帮助或仍然没有帮助,请写下;)

    您还可以添加到您的 html 代码中 例如。 :

    <span> {{progressBarValue}} </span>
    

    跟踪价值并确定它是否在变化

    【讨论】:

    • 感谢和抱歉耽搁了。我试过 {{progressBarValue}} 是的,你是真的值没有更新,但是我使用 console.log() 检查了 progressBarValue 的值按预期更改。即使在尝试了你所说的之后我也无法完成它,直到我删除了 API(window.convertMedia())。有没有其他方法可以做到这一点。提前致谢。
    • 感谢您再次检查。但是这个link 帮助了我。
    • 到底出了什么问题?变量没有更新,或者您必须使用 css/其他属性隐藏 div?
    • 是的,我不得不隐藏一个带有这个 id (progressBarValue) 的 div
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-05-14
    • 1970-01-01
    • 1970-01-01
    • 2021-09-06
    • 2020-08-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多