2017-04-04 54 views
1

我已經升級到4角和測試他們對*ngFor功能演示(點擊此處下載:http://angularjs.blogspot.si/2017/03/angular-400-now-available.html),它們分別是:角 - 官方的文檔* ngFor數演示不工作

<div *ngIf="userList | async as users; else loading"> 
    <user-profile *ngFor="let user of users; count as count" [user]="user"> 
    </user-profile> 
<div>{{count}} total users</div> 
</div> 
<ng-template #loading>Loading...</ng-template> 

count部分只是沒有按我猜這樣工作。我不確定這是否是Angular 4或2的一部分,但無論如何,它都不起作用。下面是我的例子上plnkr:

https://plnkr.co/edit/IOX558pMkRqCxpSzcTVS?p=preview

正如你所看到的其他部分做工精細,但count是空的。這種情況也發生在本地,我想這不是一個笨蛋錯誤。

+0

這Angular4只 –

+0

我使用角4裏面的元素,對不對?由於'else loading'部分起作用,所以它在plnkr上可能都很好。此外,我已經升級到本地的Angular 4,它不起作用。 – uglycode

回答

0

此變量纔可您應用*ngFor

例如

<ng-container *ngFor="let user of users; let count=count"> 
    <user-profile [user]="user"></user-profile> 
    <div>{{count}} total users</div> 
</ng-container> 

Plunker example

+0

我設法做到了這一點;在'ngFor'中使用'count'。但這不是官方文檔的例子。所以我想知道是在他們的文檔中的錯誤還是我沒有做正確的事情? – uglycode

+0

看起來像我的一個bug –

+0

呃,沒錯。 'count as count'也適用。 –