Ser*_*gan 197 angular2-template angular
我觉得我错过了什么.当我尝试data attribute在我的中使用时template,像这样:
<ol class="viewer-nav">
<li *ngFor="#section of sections" data-value="{{ section.value }}">
{{ section.text }}
</li>
</ol>
Run Code Online (Sandbox Code Playgroud)
Angular 2 崩溃:
EXCEPTION:模板解析错误:无法绑定到"sectionvalue",因为它不是已知的本机属性("
] data-sectionvalue ="{{section.value}}"> {{section.text}}
我显然遗漏了一些语法,请帮忙.
Gün*_*uer 417
请改用属性绑定语法
<ol class="viewer-nav"><li *ngFor="let section of sections"
[attr.data-sectionvalue]="section.value">{{ section.text }}</li>
</ol>
Run Code Online (Sandbox Code Playgroud)
要么
<ol class="viewer-nav"><li *ngFor="let section of sections"
attr.data-sectionvalue="{{section.value}}">{{ section.text }}</li>
</ol>
Run Code Online (Sandbox Code Playgroud)
Max*_*yov 29
关于访问
<ol class="viewer-nav">
<li *ngFor="let section of sections"
[attr.data-sectionvalue]="section.value"
(click)="get_data($event)">
{{ section.text }}
</li>
</ol>
Run Code Online (Sandbox Code Playgroud)
和
get_data(event) {
console.log(event.target.dataset.sectionvalue)
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
98357 次 |
| 最近记录: |