我正在使用Angular 4.
我有一个名为Price Difference的简单组件。我想决定是否显示标题:
<price-difference showHeader="true"></price-difference>
在PriceDifferenceComponent中:
@Input() showHeader: boolean;
在模板中:
<div class="header-container" *ngIf="showHeader == true">
<h3>some header</h3>
</div>
showHeader is {{ showHeader }}
<br />
showHeader == true is {{ showHeader == true }}
即使showHeader
为true
,标题也不会显示。在模板中,我看到:
showHeader is true
showHeader == true is false
去做那一个。
如何让模板将showHeader视为布尔值?
答案 0 :(得分:1)
您必须将<price-difference [showHeader]="true"></price-difference>
放在绑定变量周围:
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<button class="navbar-toggler navbar-toggler-right" type="button" aria-controls="#ex1" aria-expanded="false" aria-label="Toggle navigation" data-toggle="collapse" data-target="ex1">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">לוגו</a>
</div>
<div class="collapse navbar-collapse" id="ex1">
<ul class="nav navbar-nav navbar-right">
<li class="active"><a class="nav-link" href="#">דף הבית</a></li>
<li class="nav-item"><a class="nav-link" href="#">Link</a></li>
<li class="nav-item"><a class="nav-link" href="#">Link</a></li>
<li class="nav-item"><a class="nav-link" href="#">Link</a></li>
<li class="nav-item"><a class="nav-link" href="#">Link</a></li>
</ul>
</div>
</div>
</nav>