Tuo*_*nen 5 html javascript css angularjs angular
为什么Angular 2不允许我使用*ngFor在div-block中创建一组子视图?
案子:
import {Component, Input} from '@angular/core';
import {ChoiceComponent} from './choice.component';
import {Question} from './model/Question';
@Component({
selector: 'question',
template: `
<div class="panel">
{{question.text}}
<choice *ngFor="let choice of question.choices" [choice]="choice">
</div>
`,
directives: [ChoiceComponent]
})
export class QuestionComponent {
@Input()
question: Question; // Input binding from category component ngFor
}
Run Code Online (Sandbox Code Playgroud)
原因
EXCEPTION: Template parse errors:
Unexpected closing tag "div" ("
<div class="panel">
<choice *ngFor="let choice of question.choices" [choice]="choice">
[ERROR ->]</div>
"): QuestionComponent@3:4
Run Code Online (Sandbox Code Playgroud)
但是以下工作正常,但我希望在同一个面板中有问题和选择按钮.
<div class="panel">
{{question.text}}
</div>
<choice *ngFor="let choice of question.choices" [choice]="choice">
Run Code Online (Sandbox Code Playgroud)
解析器期望 <choice>标签首先关闭,直到<div>。
尝试以下
<div class="panel">
{{question.text}}
<choice *ngFor="let choice of question.choices" [choice]="choice">
</choice>
</div>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2603 次 |
| 最近记录: |