angular-arrays

Copy array of Objects in angular 2

旧街凉风 提交于 2020-03-22 07:08:25
问题 I have two array called 'persons' and 'persons2', The 'persons2' array would to be copy of 'persons' array, But the problem is when I copy it, and I want to change the second array, the first array is also changing. This is my code: export class AppComponent { persons = [ { name:'David', lname:'Jeu' } ]; persons2=[...this.persons]; constructor(){ console.log(this.persons[0]); this.persons2[0].name='Drake'; console.log(this.persons[0]); console.log(this.persons2[0]); } } 回答1: But the problem

Copy array of Objects in angular 2

自古美人都是妖i 提交于 2020-03-22 07:07:28
问题 I have two array called 'persons' and 'persons2', The 'persons2' array would to be copy of 'persons' array, But the problem is when I copy it, and I want to change the second array, the first array is also changing. This is my code: export class AppComponent { persons = [ { name:'David', lname:'Jeu' } ]; persons2=[...this.persons]; constructor(){ console.log(this.persons[0]); this.persons2[0].name='Drake'; console.log(this.persons[0]); console.log(this.persons2[0]); } } 回答1: But the problem

Angular Viewmodels and usage in components

大城市里の小女人 提交于 2020-01-14 04:08:43
问题 I'm trying to bind viewmodels to a view through component. Initially I did this in the component and it was almost working: model: any = { TenantId: '', CustomFieldName: '', quantities: [] }; quantity: any = { price: '', name: '' } Then on button click for adding new object of model I was doing this: addNewQuantity() { if (this.newQuantity) { this.quantity.name = this.newQuantity; this.model.quantity.push(this.quantity); this.newQuantity = ''; } } The issue with above event was that the same

How to filter an array and return the entire object - Angular

China☆狼群 提交于 2019-12-12 06:47:46
问题 export class ResultComponent { students: AdmissionFormData[] constructor(private adStudent: AdmissionFormService) { adStudent.adFormGet().subscribe( x => this.students = x ) } onSubmit(value) { } } In the students array, I have the data. And onSubmit is the function and value is the parameter "roll" And the HTML File: <div class="form"> <div class="col-md-5 offset-md-3"> <div class="card"> <div class="card-header text-center"> <h3 id="form_name" >Search Result</h3> </div> <div class="card