私は彼らのコメントとともに投稿を表示しています。コメントのない投稿についてはその投稿に対するコメントがないので、設定しようとしました角4 - テンプレートエラーでelseを使用する場合
<li *ngFor="let post of posts" (click)="select(post)" >
{{ post.Summary }}
<ul *ngIf="currentPost == post && commentsVisible">
<li *ngIf="currentPost.comments.length > 0;else message" *ngFor="let comment of currentPost.comments" class="comment">
<p>{{ comment.Name }}</p>
<p>{{ comment.TemplateName }}</p>
<p>{{ comment.CreatedByUserName }}</p>
<p>{{ comment.Preview }}</p>
</li>
<ng-template #message>No comments for {{ post.Title }}</ng-template>
</ul>
</li>
私はエラーを取得する:このよう
Unhandled Promise rejection: Template parse errors:
Can't have multiple template bindings on one element. Use only one attribute named 'template'
ただ、もう少しコンテキストを追加する - すべての[構造のディレクティブ](https://angular.io/docs/ts/latest/guide/structural-directives.html#the-asterisk-prefix)(すなわち'*'で始まるもの)は 'template'属性にコンパイルされます。なぜなら、なぜ複数を持つことができないのか、なぜエラーメッセージがそれなのかを説明しているからです。 –
@JoeClayはい、これは本当です。私はそれを追加します。ありがとう、 –
私はあなたと同じことをしていますが、エラーはなくなりましたが、メッセージはテンプレートに表示されません。 – Leff