为什么当我在信号商店(在服务中)时
服务
protected static readonly removedAllowances: WritableSignal<(ContractAllowanceDTO)[]> = signal<(ContractAllowanceDTO})[]>([]);
/* getters */
public getRemovedllowances() {
return computed(() => ContractService.removedAllowances())
}
组件
在组件类中
protected readonly removedAllowances = this.contractService.getRemovedAllowances();
let removedAllowances: any[];
removedAllowances = this.removedAllowances();
removedAllowances.pop();
console.log('allowance', this.contractService.getRemovedAllowances()())
控制台记录结果,就好像服务中的变量 ContractService.removedAllowances() 也已被弹出。我以为信号是只读的?为什么removedAllowances.pop()会影响ContractService.removedAllowances()?
当实际值发生变化时信号会触发(1!= 2 -> 更改触发)
作为参考存储在内存中。
内存引用更改时会触发信号( memref != memref2 更改触发)
此外,当您更改非基本类型的嵌套属性时,引用不会更改!