As you can see in the code, i tried to dynamically create array values inside an object, it doesn’t have a problem when debugging, but when i tried to use push method in the array it throws an error.I am working on Angular 4 with Typescript.
private newsFeeds=[
{
avatarUrl:'../assets/fb/avatar.png',
userName:'Karim Benzema',
time:'16 minutes ago',
caption:'Wow!!!',
imageUrl:'https://upload.wikimedia.org/wikipedia/commons/e/ec/Ara_ararauna_Luc_Viatour.jpg',
like:'Like',
numberOfLikes:2,
comments:["hello"],
isCommentEnable:false
},
{
avatarUrl:'../assets/fb/avatar2.png',
userName:'Unknown Singh',
time:'2 hrs ago',
caption:'Pc:Unknown',
imageUrl:'https://i.pinimg.com/736x/50/e0/b6/50e0b65efd2d634053d7a8d1cd9d94fc--so-funny-funny-
stuff.jpg',
like:'Like',
numberOfLikes:3,
comments:[],
isCommentEnable:false
}
];
postComment(index,value){
console.log(index);
console.log(this.newsFeeds[index]);
this.newsFeeds[index].comments.push(value.toString()); //Throws runtime error 'comments.push is
//not a function'
}