2017-04-20 69 views
5

我不断收到ngIf别的工作不

不能绑定到“ngIfElse”,因为它不是“UL”的已知属性的错误。

我确定某处我犯了一个愚蠢的错误,但找不到它。

<ul *ngIf="!finished; else elseBlock" id='time'> 
    <li id='hour' class="chart" data-percent="100"><span>{{hour}} </span></li> 
    <li id='min' class="chart" data-percent="100"><span>{{minute}}</span></li> 
    <li id='second' class="chart" data-percent="100"><span>{{second}}</span></li> 
</ul> 
<ng-template #elseBlock> <h4 id='time'>DONE</h4> </ng-template> 

回答

2

ng-if指令只处理阳性病例。为否定的情况下(在else)使用一个单独的块:

<ul ng-if="!finished" id="time"> 
    <li id='hour' class="chart" data-percent="100"><span>{{hour}} </span></li> 
    <li id='min' class="chart" data-percent="100"><span>{{minute}}</span></li> 
    <li id='second' class="chart" data-percent="100"><span>{{second}}</span></li> 
</ul> 
<ng-if="finished"> 
    <h4 id='time'>DONE</h4> 
</ng-template> 
+0

虽然角度版本2不支持ng-if-else,但角度版本4现在具有此功能。 – Pengyy

+0

....不好意思,但是吧?为什么我的帖子被拒绝投票? –

+0

我已经反击downvote。 –

5

角2不支持Esle,您有2种选择:

1:使用肯定的情况下:

<ul *ngIf="!finished" id="time"> 
    <li id='hour' class="chart" data-percent="100"><span>{{hour}} </span></li> 
    <li id='min' class="chart" data-percent="100"><span>{{minute}}</span></li> 
    <li id='second' class="chart" data-percent="100"><span>{{second}}</span</li> 
</ul> 
<h4 id="time" *ngIf="finished"> <!-- this --> 
    DONE 
</h4> 

2 :将您的应用更新到Angular 4:

在Linux/Mac上:

npm install @angular/{common,compiler,compiler-cli,core,forms,http,platform-browser,platform-browser-dynamic,platform-server,router,animations}@latest [email protected] --save 

在Windows上:

npm install @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] @angular/[email protected] [email protected] --save 

如果依靠动画,从 导入新BrowserAnimationsModule @在你的根NgModule角/平台的浏览器/动画。没有 这个,你的代码将被编译并运行,但是动画会触发一个 错误。来自@ angular/core的进口已被弃用,从'@ angular/animations';使用从 导入的新包import {trigger,state,style,transition,animate} 。

http://angularjs.blogspot.com/2017/03/angular-400-now-available.html

0

我看不出有什么不对的代码。

<ng-container *ngIf="!loading;else preloader"> 
    <p>Loaded stuff here!!!!!</p> 
</ng-container> 
<ng-template #preloader> 
    <div class="progress"> 
     <div class="indeterminate"></div> 
    </div> 
</ng-template> 

我会确保你运行的是Angular 4.0。由于上述海报是正确的,因此角度2不支持此功能。