我正在使用角度2.3.0。我收到了下一条消息:
无法绑定到'type',因为它不是'alert'的已知属性。
模板相关代码是(here上的完整模板代码):
<alert *ngFor="let alert of alerts; let i = index" [type]="alert.type + ' alert-sm'" (close)="closeAlert(i)" dismissible="true">
<div [innerHTML]="alert.msg"></div>
</alert>
你可以猜到,我从alert
属性获得了每个alerts
。
组件相关代码:
@Component({
selector: 'signin',
styleUrls: [ './signin.style.scss' ],
templateUrl: './signin.template.html',
encapsulation: ViewEncapsulation.None,
host: {
class: 'signin-page app'
},
providers: [ UsersService ]
})
export class Signin implements OnInit {
private alerts: Array<Object>;
constructor()
{
this.alerts = [
{
type: 'success',
msg: '<span class="fw-semi-bold">Success:</span> You successfully read this important alert message.'
}];
}
}
我不知道出了什么问题。有什么想法吗?
答案 0 :(得分:0)
更改HTML,如下所示:
<div *ngFor="let alert of alerts; let i = index" [attr.type]="alert.type + ' alert-sm'" (close)="closeAlert(i)" dismissible="true">
<div [innerHTML]="alert.msg"></div>
</div>