How can I create array of class and then push some classes in it , I just have to create same as
In C#
public class CheckBoxListItem
{
public string DisplayName { get; set; }
public string Value { get; set; }
public bool IsChecked { get; set; }
}
List<CheckBoxListItem> cbx = new List<CheckBoxListItem>();
cbx.Add(new CheckBoxListItem(){DisplayName ="ABC",Value="NOW",IsChecked=true});
In Typescript
class Graph{
graphType:string;
checkedItems:CheckBoxListItem[];
}
class CheckBoxListItem
{
DisplayName: string
Value:string
IsChecked:boolean
}
Properties
checksGraph :CheckBoxListItem;
graphModel:Graph;
Constructor
constructor(private el:ElementRef, private renderer:Renderer) {
this.checksGraph = new CheckBoxListItem();
this.graphModel = new Graph();
}
Problem
pushItem(){
this.checksGraph.DisplayName=displayName;
this.checksGraph.Value=value;
this.checksGraph.IsChecked=check;
this.graphModel.checkedItems.push(this.checksGraph);
}
This line could not run becuase checkedItems is undefined
this.graphModel.checkedItems.push(this.checksGraph);
also cannot use
this.graphModel.checkedItems = new CheckBoxListItem[50];
this throws TypeError: CheckBoxListItem[50] is not a constructor.