我正在做一个项目(Ionic3和Angular5)。
我从外部.js文件中更改了以下输入中的值
<input [(ngModel)]="name"
(ngModelChange)="valueChange()"
id="data">但是函数valueChange()不被调用。
我以前在Angular1中使用$scope.$apply做过这件事,但是在Angular5中我不知道如何做同样的事情。在Angular5中这样做的等效方式是什么?
发布于 2018-05-05 08:04:24
markForCheck():将所有ChangeDetectionStrategy祖先标记为要检查。detectChanges():检查变更检测器及其子程序。
例子:-
import { Component,
Input,
ChangeDetectionStrategy,
ChangeDetectorRef } from '@angular/core';
@Component({
selector: 'app-child',
templateUrl: './child.component.html',
changeDetection: ChangeDetectionStrategy.OnPush
})
export class ChildComponent {
@Input() data: string[];
constructor(private cd: ChangeDetectorRef) {}
refresh() {
this.cd.detectChanges();
}
}这是一篇非常好的关于角度变化检测的文章:- https://alligator.io/angular/change-detection-strategy/
https://stackoverflow.com/questions/50187128
复制相似问题