@Input不会得到更新值-Angular



我在一个组件中有许多数组,我需要为sun的组件传递这些信息。我认为这是通过@Input方法实现的。在父组件中,我在that数组中进行了多次推送。完成推送后,我需要将@Input提供给子组件。但我尝试的方式是获取数组的初始值,比如0或空。有人能帮我吗?

父组件HTML:

<div class="past-information">
<app-lunch-review-dialog [namePackage]="packageName" [estaticValue]="valueEstatic" 
[valueBag]="packageValue" [linkImage]="packageImage" [amountBag]="packageAmount" 
[finalValueBag]="sum"></app-lunch-review-dialog>
</div>

Sun组件TS:

@Input() namePackage: Array<string> = []
@Input() estaticValue: Array<string> = []
@Input() valueBag: Array<string> = []
@Input() linkImage: Array<string> = []
@Input() amountBag: Array<string> = []
@Input() finalValueBag: number;

父代码填充数组:

let bagValue = this.packageSelected.value.toString()
let bagName = this.packageSelected.name
let bagAmount = this.packageSelected.bagAmount.toString()
let bagImage = this.packageSelected.imagePath
this.packageName.push(bagName);
this.valueEstatic.push(bagValue)
this.packageValue.push(bagValue);
this.packageImage.push(bagImage);
this.packageAmount.push(bagAmount);

我如何在子组件中调用@Input:

ngOnInit(){
console.log("@Input NP is " + this.namePackage);
console.log("@Input EV is " + this.estaticValue);
console.log("@Input VB is " + this.valueBag);
console.log("@Input LI is " + this.linkImage);
console.log("@Input AB is " + this.amountBag);
console.log("@Input FVB is " + this.finalValueBag);
}

当我调用console.log时,它以这种方式返回:console.log

推送时,引用不会更改,因此子组件不会刷新。因此,尝试在推送后更改原始数组的引用。

例如:

在父组件中,

this.packageName.push("something");
this.packageName = [...this.packageName]

最新更新