[Augular]Push is not defined in the array
I am new to Angular. However, I have used AnuglarJS for a year. That is very hard to catch up. Today, I found a silly error. I cannot add an element to an array by using Pushj function. I got an error,Push is not defined.
students : Person[];
constructor(){
var newPerson = new Person();
this.students.push(newPerson);
}
Finally, I found, I am so silly. The array is not initialized yet.
I need to do that.
students : Person[];
constructor(){
this.students = []
var newPerson = new Person();
this.students.push(newPerson);
}
Trackback address for this post
Trackback URL (right click and copy shortcut/link location)
Feedback awaiting moderation
This post has 32 feedbacks awaiting moderation...
Form is loading...