gpt4 book ai didi

angular - Nativescript - 我的组件中不存在 ChangeDetectorRef

转载 作者:行者123 更新时间:2023-12-02 20:10:25 26 4
gpt4 key购买 nike

我尝试自动更新 ListView 中使用的数组。为此,我使用 ChangeDetectorRef,如下所示:

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();
}

但是,我收到此错误:

error TS2339: Property 'cdr' does not exist on type 'RegisterComponent'.

有人可以解释一下我的误解吗?

最佳答案

它是构造函数中的局部变量,直到您添加像 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();
}

关于angular - Nativescript - 我的组件中不存在 ChangeDetectorRef,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53732775/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com