2017-06-01 8 views
1

私は角度のアプリを持っています。これは、* ngFor からカラムのインデックスを取得し、それをHTMLエレメントに追加したいのですが、の例を試しましたが、エラーが発生します。angle - * ngForインデックス付き

コード:

<li *ngFor="let col of Descriptive_FieldsMap;let i = index;"> 
    <a class="ShowHideColumns" data-columnindex="{{i + 1}}"> 
     {{col.FieldName}} 
    <i id="data-table-col-{{i + 1}}" class="fa fa-minus-square pull-right"> 
    </i> 
    </a> 
</li> 

がエラー:

Error: Template parse errors:↵Can't bind to 'columnindex' since it isn't a known property of 'a'. ("tive_FieldsMap;let i = index;"> 
↵ 
+0

エラーがデータcolumnindex'が ' – Arijoon

答えて

3

data-columnindex<a>タグあなたのネイティブの属性ではありませんので、別のアプローチをとらなければならない。 attrディレクティブでバインドします

<a class="ShowHideColumns" [attr.data-columnindex]="i + 1"> 

https://angular.io/docs/ts/latest/guide/template-syntax.html#!#other-bindings

+0

おかげでたくさんの'のための有効な属性ではありません 'と言っているようだ、それが働きました – tyehia

関連する問題