Monday, August 19, 2019

How to add object to array angular 7

How to add object to array angular 7

Add items in array angular, how to add item to array in angular 7 Often we want to add object in an array on the programming language for Android, java, c ++ .. then we declare an object and then perform add it in the array, those with language programmable angular then you do the same
but with one difference is that you must declare the array like.
How to add object to array angular 7

Here is the implementation add object in the array with angular 7.
Step 1. Create class object in angular 7
export class fengxiang{
  constructor(public timestamp:string,public direction: number){
  }
or you can create class below:
export class CoDeAndroid{
   title: string;
   value: number;
}
Step 2. Create a array with object CoDeAndroid
 arrayCode : CoDeAndroid[] = [];
Step 3. insert object in array

let code = new CoDeAndroid();
 code.title ="Code Android Example";
 code.value = 123466;
 this.arrayCode.push(code);
Above is the article below about how to add item in array angular 7 if you feel the article is useful for you, please press like like or share your post.
Thank you everyone.

No comments:

Post a Comment