Angular 2 declaring an array of objects

前端 未结 7 2094
-上瘾入骨i
-上瘾入骨i 2020-12-13 08:48

I have the following expression:

public mySentences:Array = [
    {id: 1, text: \'Sentence 1\'},
    {id: 2, text: \'Sentence 2\'},
    {id: 3,         


        
7条回答
  •  悲哀的现实
    2020-12-13 09:24

    Datatype: array_name:datatype[]=[]; Example string: users:string[]=[];

    For array of objects:

    Objecttype: object_name:objecttype[]=[{}]; Example user: Users:user[]=[{}];

    And if in some cases it's coming undefined in binding, make sure to initialize it on Oninit().

提交回复
热议问题