2017-01-24 8 views
-1

新しいanglejsです。Angularjs 2ネストされたインターフェイス

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

HTML::はダイナミックのため* ngForをやって私もこの1

インタフェース

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

モデルを説明する方法を知っているカントコードを見てください。入力フィールド

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

しかし

未定義

field12の

プロパティを読み取ることができませんとしてこの1つはエラーをスロー 'field12は、' 動的な値がlist.fieldNameから来ています。 私はこの問題を解決する方法を知らない。どのような解決策もありがとうございます。前もって感謝します。

+0

ここでcustomFieldsを初期化していますか?それは、holeDocument.customFieldsが定義されていないと私のインターフェイスでは –

+0

、私のインターフェイスヘッダーの2行目を参照し、モデルでインポートされて1行目を参照@ AliBaig – sibi

+0

それは単に宣言ではなく、初期化です。私が見る限り、=演算子を使ってcustomFieldsに何も割り当てていません。 –

答えて

-1

はい、私はngOnInitでオブジェクトを初期化して修正しました。 コード: インタフェース:

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

モデル:

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

HTML:ダイナミック入力フィールド

<input id="{{list.fieldName}}" name="{{list.fieldName}}" type="{{list.fieldType}}" class="form-control" [(ngModel)]="holeDocument.customFields[list.fieldName]" > 
ため * ngForを行います

ご返信いただきありがとうございます。

関連する問題