I try to automatically update an array used in a Listview. To do that, I use ChangeDetectorRef like this :
import { Component, OnInit, ChangeDetectionStrategy, Input, ChangeDetectorRef } from "@angular/core";
@Component({
selector: "register",
templateUrl: "./register.html",
styleUrls: ["./register.css"],
changeDetection: ChangeDetectionStrategy.OnPush
})
export class RegisterComponent implements OnInit {
@Input regis = Array<string>;
constructor(cdr: ChangeDetectorRef){}
ngAfterContentChecked() {
this.cdr.detectChanges();
}
However, I get this error :
error TS2339: Property 'cdr' does not exist on type 'RegisterComponent'.
Could someone explain me what I misunderstood ?
It's a local variable within constructor until you add a accessor like public / private.
import { Component, OnInit, ChangeDetectionStrategy, Input, ChangeDetectorRef } from "@angular/core";
@Component({
selector: "register",
templateUrl: "./register.html",
styleUrls: ["./register.css"],
changeDetection: ChangeDetectionStrategy.OnPush
})
export class RegisterComponent implements OnInit {
@Input regis = Array<string>;
constructor(private cdr: ChangeDetectorRef){}
ngAfterContentChecked() {
this.cdr.detectChanges();
}