【发布时间】:2016-09-27 04:32:56
【问题描述】:
为什么 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
}
原因
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
但是以下工作正常,但我希望在同一个面板内有问题和选择按钮。
<div class="panel">
{{question.text}}
</div>
<choice *ngFor="let choice of question.choices" [choice]="choice">
【问题讨论】:
标签: javascript html css angularjs angular