2017-01-24 2 views
-1

Bin neu bei angularjs. bitte den Code buchen, ich kann nicht einmal wissen, wie diese einAngularjs 2 verschachtelte Schnittstelle

export interface ScanuploadInterface { 
    docVia string;customFields:Array<any>; 
    associateDocs :Array<any>; 
} 

Modell

Schnittstelle zu erklären:

import {ScanuploadInterface} from '../../interfaces/scanupload.interface'; 
holeDocument = <ScanuploadInterface>{}; 

html:tun * ngFor für dynamische Eingabefelder

<input id="{{list.fieldName}}" name="{{list.fieldName}}" type="{{list.fieldType}}" class="form-control" [(ngModel)]="holeDocument.customFields[list.fieldName]" > 

aber dieser wirft einen Fehler als

Kann nicht Eigentum 'field12' undefinierter

field12 ist ein dynamischer Wert kommt von list.fieldName lesen. Ich weiß nicht, wie ich das lösen soll. Jede Art von Lösung wird geschätzt. Danke im Voraus.

+0

Wo initialisieren Sie Ihre customFields? Es heißt, lochDocument.customFields ist undefined –

+0

an meiner Schnittstelle, siehe 2. Zeile in meiner Schnittstelle Header und importiert am Modell siehe 1. Zeile. @ AliBaig – sibi

+0

Das ist nur die Erklärung, nicht die Initialisierung. Soweit ich sehen kann, haben Sie customFields mit = = operator nichts zugewiesen. –

Antwort

-1

ja, ich habe durch die Initialisierung des Objekts in ngOnInit behoben, es funktioniert. Code: Schnittstelle:

export interface ScanuploadInterface { 
    docVia string;customFields:any; 
    associateDocs :any; 
} 

Modell:

import {ScanuploadInterface} from '../../interfaces/scanupload.interface'; 
holeDocument = <ScanuploadInterface>{}; ngOnInit(){this.holeDocument.customFields = {}; 
     this.holeDocument.associateDocs = {};} 

html:* ngFor für dynamische Eingabefelder tun

<input id="{{list.fieldName}}" name="{{list.fieldName}}" type="{{list.fieldType}}" class="form-control" [(ngModel)]="holeDocument.customFields[list.fieldName]" > 

Vielen Dank für Ihre Antwort Jungs.