我有来自角度2的以下错误:
EXCEPTION: Template parse errors:
Parser Error: Unexpected token . at column 26 in [ngFor let button of modal.buttons] in ModalComponent@11:22 ("">
<button type="button" class="btn" data-dismiss="modal"
[ERROR ->]*ngFor="let button of modal.buttons"
[ngClass]="button.classes"
"): ModalComponent@11:22
这是我的代码:
import {Component} from 'angular2/core';
import {NgFor, NgClass} from 'angular2/common';
import {EventService} from '../services/event.service';
interface Button {
text: string;
classes: Array<string>;
clicked: Function;
}
interface Modal {
title: string;
text: string;
buttons: Array<Button>;
}
@Component({
selector: 'modal',
template: `<div *ngIf="modal" class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<h4 class="modal-title">{{modal.title}}</h4>
</div>
<div class="modal-body" [innerHTML]="modal.text"></div>
<div class="modal-footer">
<button type="button" class="btn" data-dismiss="modal"
*ngFor="let button of modal.buttons"
[ngClass]="button.classes"
>{{button.text}}</button>
</div>
</div>
</div>`,
directives: [NgFor, NgClass]
})
export class ModalComponent {
modalElement: HTMLElement;
modal: Modal = [...];
[...]
}
我尝试生成一个模态组件,没有按钮它可以正常工作。为什么这是错误的?为什么不能对对象子数组进行角度迭代?我正在寻找几个小时,请帮忙