在ionic2中隐藏元素:无法绑定到'* ngIf',因为它不是已知的本机属性 [英] Hiding element in ionic2: Can't bind to '*ngIf' since it isn't a known native property
本文介绍了在ionic2中隐藏元素:无法绑定到'* ngIf',因为它不是已知的本机属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的ionic2应用程序中的DOM元素有问题。当我尝试做这样的事情时:
< ion-tabs>
< ion-tab [root] =tab1RoottabTitle =el1tabIcon =list-box>< / ion-tab>
将离子标签[根] = tab2Root tabTitle = EL2 tabIcon = GIT-拉请求 >< /离子标签>
< div * ngIf ='admin'=='admin'>
< ion-tab [root] =tab4RoottabTitle =AdmintabIcon =cog>< / ion-tab>
< / div>
< ion-tab [root] =tab3RoottabTitle =ProfiletabIcon =person>< / ion-tab>
< / ion-tabs>
一切正常。但是当我在构造函数中设置angular变量时:
export class TabsPage {
constructor(){
this .userRole =admin;
和
<离子突片>
< ion-tab [root] =tab1RoottabTitle =el1tabIcon =list-box>< / ion-tab>
< ion-tab [root] =tab2RoottabTitle =el2tabIcon =git-pull-request>< / ion-tab>
< div * ngIf ={{userRole}} =='admin'>
< ion-tab [root] =tab4RoottabTitle =AdmintabIcon =cog>< / ion-tab>
< / div>
< ion-tab [root] =tab3RoottabTitle =ProfiletabIcon =person>< / ion-tab>
< / ion-tabs>
该应用程序返回错误信息:
无法绑定到'* ngIf',因为它不是已知的本机属性
如何当 userRole ='admin'
?
解决方案
时,我可以隐藏此元素 * ngIf =expression
的条件表达式已经即将评估,无需使用 {{}}
。
'p>所以
< DIV * ngIf ={{的UserRole}} ==管理员>
应该是
< div * ngIf =userRole =='admin'>
I have a problem with DOM elements in my ionic2 app. When I trying do something like this:
<ion-tabs>
<ion-tab [root]="tab1Root" tabTitle="el1" tabIcon="list-box"></ion-tab>
<ion-tab [root]="tab2Root" tabTitle="el2" tabIcon="git-pull-request"></ion-tab>
<div *ngIf="'admin'=='admin'">
<ion-tab [root]="tab4Root" tabTitle="Admin" tabIcon="cog"></ion-tab>
</div>
<ion-tab [root]="tab3Root" tabTitle="Profile" tabIcon="person"></ion-tab>
</ion-tabs>
everything is OK. But when I set angular variable in constructor:
export class TabsPage {
constructor() {
this.userRole = "admin";
and
<ion-tabs>
<ion-tab [root]="tab1Root" tabTitle="el1" tabIcon="list-box"></ion-tab>
<ion-tab [root]="tab2Root" tabTitle="el2" tabIcon="git-pull-request"></ion-tab>
<div *ngIf="{{userRole}}=='admin'">
<ion-tab [root]="tab4Root" tabTitle="Admin" tabIcon="cog"></ion-tab>
</div>
<ion-tab [root]="tab3Root" tabTitle="Profile" tabIcon="person"></ion-tab>
</ion-tabs>
the application returns me an error:
Can't bind to '*ngIf' since it isn't a known native property
How I can hide this element when userRole = 'admin'
?
解决方案
The condition expression at *ngIf="expression"
is already going to be evaluated, no need to use {{}}
.
So
<div *ngIf="{{userRole}}=='admin'">
should really be
<div *ngIf="userRole=='admin'">
这篇关于在ionic2中隐藏元素:无法绑定到'* ngIf',因为它不是已知的本机属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文