1
saveOccuraces(currentFrequency: Frequencies) {
var freq = new Frequencies();
freq = currentFrequency;
// freq.occurance = currentFrequency.occurance; // <--Problem is here
this.selectedFrequencies.push(freq);
}
<md-input-container>
<input type="number" [(ngModel)]="currentFrequency.occurance" mdInput placeholder="Every" name="occurance">
</md-input-container>
<button md-icon-button (click)="saveOccuraces(currentFrequency)">
<md-icon>add</md-icon>
</button>
在上面的代碼,如果我執行,因爲它是所有發生值與新的更新,如果我評論freq=currentFrequency;
線和未註釋freq.occurance = currentFrequency.occurance;
那麼它工作正常。代替參考添加對象值到新的變量類型腳本
是否有任何替代推動與值對象只(withou
你是什麼意思(withou ?? – k11k2
你在說什麼https://docs.angularjs.org/api/ng/function/angular.copy – InferOn
[angular.copy()和賦值(=)]之間的差異可能重複(https://stackoverflow.com/questions/29749433/angular-copy-and-assignment之間的差異) – InferOn