I have a strange issue, I am using a dataview so when I add items to the array is not pushing to the array. i used chrome developer tool to confirm that nothing is being pushed to the array.
HTM (just showing the checkboxed for simplicity)
<p-dataView [value]="iErsaPreviewApps" [paginator]="true" [rows]="20" [sortField]="sortField" [sortOrder]="sortOrder" paginatorPosition="both">
<ng-template let-prev pTemplate="listItem">
<input type="checkbox" id="cbPreviewID" checked name="cbxPreview" (click)="togglePreviewApp($event)" style="margin-right:5px;margin-bottom:10px;margin-left:5px; margin-top:10px" [value]='prev.app_id'> {{prev.app_name}}
</ng-template>
</p-dataView>
interface
export interface IErsaApps {
app_id: number;
app_type_id: number;
app_name: string;
app_roles: string;
app_sort_id?: number;
roles: Array<IErsaAppRoles>
}
export interface IErsaAppRoles {
app_role_id: number;
app_role_app_id: number;
app_role_name: string;
app_role_sort_id?: number;
}
Service
getErsaApps(): Observable<IErsaApps[]> {
return this._http.get(environment.BASE_API_URL + 'xxxxxx')
.map((response: Response) => <IErsaApps[]>response.json())
.catch(this.handleError);
}
TS
iErsaAppList: IErsaApps[] = [];
selectedObject: IErsaApps;
selectedPreviewObject: IErsaApps;
iErsaDeafultApps: IErsaApps[] =[];
iErsaPreviewApps: IErsaApps[]=[];
iErsaSelectedApps: IErsaApps[] = null;
ngOnInit() {
this.GetErsaApps();
}
GetErsaApps() {
this._ersaDet.getErsaApps()
.subscribe(
data => {
this.iErsaDefaultApps = data;
this.iErsaAppList = data.map(item => item); },
}
togglePreviewApp(event: any) {
if (this.iErsaAppList != undefined) {
this.selectedPreviewObject = this.iErsaAppList
.find(x => x.app_id == event.srcElement.value);
const index: number = this.iErsaPreviewApps.indexOf(this.selectedPreviewObject);
this.iErsaDeafultApps.push(this.selectedPreviewObject);
}
}