Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 进度条不显示';t更新角度_Javascript_Angular_Typescript_Progress Bar_Angular6 - Fatal编程技术网

Javascript 进度条不显示';t更新角度

Javascript 进度条不显示';t更新角度,javascript,angular,typescript,progress-bar,angular6,Javascript,Angular,Typescript,Progress Bar,Angular6,假设我有一个html组件,其中有我的html 我打印的值是正确的。它是根据另一种算法增加的。console.log显示正确的incremame,但进度条中的“我的百分比”值没有增加。任何人都可以帮助我吗?由于您的值在订阅中正确更新,但在模板中没有更新,因此更改检测无法注册新值。您可以手动触发更改检测,但不应该 我建议使用async管道。从而将您的用法改写为: <round-progress #progress [current]="current$ | async" </ro

假设我有一个html组件,其中有我的html


我打印的值是正确的。它是根据另一种算法增加的。console.log显示正确的incremame,但进度条中的“我的百分比”值没有增加。任何人都可以帮助我吗?

由于您的值在订阅中正确更新,但在模板中没有更新,因此更改检测无法注册新值。您可以手动触发更改检测,但不应该

我建议使用
async
管道。从而将您的用法改写为:

<round-progress #progress
    [current]="current$ | async"
</round-progress>

作为奖励,您不必再管理您的订阅。如果您在本地出于其他目的需要“当前”值,您可以共享可观察值(并且必须再次管理订阅),也可以添加一个设置本地值的点击。

round progress组件如何使用当前值?它和它有什么关系?尝试将
{{current}}
添加到模板中,并查看该值是否更新。如果是这样的话,round progress组件很可能只读取当前值一次。@Arne我将{current}}放进去,并且该值不是每次百分比增加时都更新,而是显示为0值和100值,但不显示20%或35%。我不知道我要做什么才能更新这一轮进度您的解决方案无效!:(该值不是更新。现在我尝试将markForCheck和detectionChanges放在Subscriptive值之后,但它们的工作方式不同!如果您在扫描(管道的第二个参数)下添加
点击(value=>console.log('my new value:',value)
,您会看到值更新吗?如果您在模板中添加
{current$| async}}
该值不更新?是的,在console.log中,该值是更新的,但在html中没有以正确的方式更新!我真的很好奇您在该组件中做了什么,以及代码的其余部分是什么样子的。当您完全禁用角度变化检测时,异步管道甚至可以工作。
    this.percentageSubscription=this.percentageService.percentage$.subscribe((percentage)=>{

          this.current=this.current+percentage;
console.log(this.current);

        });
<round-progress #progress
    [current]="current$ | async"
</round-progress>
this.current$ = this.percentageService.percentage$.pipe(
  scan((acc = 0, percentage) => acc + percentage)    
);