[英]angular2: property binding not found
I'm getting this message from angular2 when component+template
is rendered: 呈现
component+template
时,我从angular2收到此消息:
Can't bind to 'type' since it isn't a known property of 'alert'.
无法绑定到“类型”,因为它不是“警报”的已知属性。
I've created this component: 我创建了这个组件:
interface Alert {
type: string;
msg: string;
}
@Component({
selector: 'signin',
styleUrls: [ './signin.style.scss' ],
templateUrl: './signin.template.html',
encapsulation: ViewEncapsulation.None,
host: {
class: 'signin-page app'
}
})
export class Signin implements OnInit {
private form:FormGroup;
private alerts: Array<Alert>;
constructor(private fb: FormBuilder, private commty: UsersService) {}
ngOnInit():void {
//...
}
private addAlert(message: string): void {
this.alerts.push({type: 'danger', msg: message});
}
public closeAlert(index): void {
this.alerts.splice(index, 1);
};
}
The related html template code is: 相关的html模板代码为:
<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>
type is not default attr of html dom element(alert dom is shadow dom
) 类型不是html dom元素的默认属性(警告dom是
shadow dom
)
https://developer.mozilla.org/en-US/docs/Web/Web_Components/Shadow_DOM https://developer.mozilla.org/zh-CN/docs/Web/Web_Components/Shadow_DOM
<alert *ngFor="let alert of alerts; let i = index" [attr.type]="alert.type + ' alert-sm'" (close)="closeAlert(i)" dismissible="true">
<div [innerHTML]="alert.msg"></div>
</alert>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.