InnerHTML *ngIf 不工作 Angular5
InnerHTML *ngIf does not work Angular5
为了在 GIS openlayers 地图上显示弹出窗口,我使用了 InnerHtml 属性。
如果某个字段为假,我想隐藏的是 DIV.
看起来 angular 忽略了我的 ngif 这是我的代码:
this.content.innerHTML = `
<div style="width: 150px; float: right; font-size: 13px;" *ngIf="!test">
${ test }
</div> `
我的布尔测试是错误的。 ngIf 真的不能与 innerHTML 一起工作吗?
非常感谢
当您使用 innerHTML
时,Angular 不会招待您的 *ngIf
每当您通过 innerHTML 传递一些内容时,Angular 只会呈现该内容,不会像您通过添加 ngIf
事件那样评估该内容中的任何表达式或绑定。
您需要添加和删除如下样式
constructor(private elRef: ElementRef) {
this.elRef.nativeElement.querySelector('#showResponsiveNavbarone')
.classList.remove('visibletrue');
}
<style>
.visiblefalse{
display: none !important;
}
.visibletrue{
display: block !important;
}
为了在 GIS openlayers 地图上显示弹出窗口,我使用了 InnerHtml 属性。 如果某个字段为假,我想隐藏的是 DIV.
看起来 angular 忽略了我的 ngif 这是我的代码:
this.content.innerHTML = `
<div style="width: 150px; float: right; font-size: 13px;" *ngIf="!test">
${ test }
</div> `
我的布尔测试是错误的。 ngIf 真的不能与 innerHTML 一起工作吗?
非常感谢
innerHTML
时,Angular 不会招待您的 *ngIf
每当您通过 innerHTML 传递一些内容时,Angular 只会呈现该内容,不会像您通过添加 ngIf
事件那样评估该内容中的任何表达式或绑定。
您需要添加和删除如下样式
constructor(private elRef: ElementRef) {
this.elRef.nativeElement.querySelector('#showResponsiveNavbarone')
.classList.remove('visibletrue');
}
<style>
.visiblefalse{
display: none !important;
}
.visibletrue{
display: block !important;
}