Error while adding “for” attribute to label in angular 2.0 template

后端 未结 1 1713
悲哀的现实
悲哀的现实 2021-01-04 00:20

I use the Angular 2.0 framework and try to create an input component. Also I use Google MDL and it\'s HTML structure required to have labels to input. Angular gives me an e

相关标签:
1条回答
  • 2021-01-04 00:44

    update

    In recent Angular2 versions for should be mapped to htmlFor automatically to avoid this kind of problem.

    original

    You need attribute binding instead of proper binding

    <label class="mdl-textfield__label" attr.for="{{input_id}}">{{input_label}}</label>
    

    or

     <label class="mdl-textfield__label" [attr.for]="input_id">{{input_label}}</label>
    

    or

    <label class="mdl-textfield__label" htmlFor="{{input_id}}">{{input_label}}</label>
    

    htmlFor is the property that reflects the for attribute (https://developer.mozilla.org/de/docs/Web/API/HTMLLabelElement)

    See also HTML - attributes vs properties

    0 讨论(0)
提交回复
热议问题