I made an array like this in angular2, and also I made a form to fill out a table and it works well. But my question is what is the best way to put some values in this array without filling the form, I want some content already in this array.
employeeList = new Array<{name:string, bio:string, job:string, salery:string, url:string}>();
Create a class representing your structure:
export class User {
name: string;
bio: string;
job: string;
salary: string;
url: string
constructor(_name: string, _bio: string, _job: string, _salary: string, _url: string) {
this.name = _name; this.bio = _bio; this.job = _job; this.salary = _salary; this.url = _url;
}
}
or like this:
export class User {
constructor(public name: string,
public bio: string,
public job: string,
public salary: string,
public url: string) {
}
}
You array will look like this:
users: User[] = []; // if it's a class member
var users: User[] = []; // if it's a local variable
Add something to array:
this.users.push(
new User("Bob", "", "Developer", "100", "github.com");
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With