如何使用ngfor打印对象的属性?

时间:2016-09-17 13:49:23

标签: json angular

<div *ngFor="let article of articleList;let i = index">
                    <div class="item">
                    <div class="image-holder"
                         style="background-image: url(https://c9.io/blog/content/images/2015/07/ninja-1.jpg)">
                        <a href="https://c9.io/blog/title-wip-cloud9-shortcutfoo/"></a>
                    </div>
                    <div class="title">
                        <a class="title-ref" href="#">{{article.title}}</a>
                    </div>
                    <div class="text">
                        <div>
                            {{article.description}} <a class="text-ref" href="#">>></a>
                        </div>
                    </div>
                    <div class="item-header">
                        <div class="author">
                            <img class="img-circle"
                                 src="https://c9.io/blog/content/images/2015/05/brady.jpg" />
                        </div>
                        <span class="author-name"><a class="user-ref" href="#">{{article.user.name}}</a></span>
                        <div class="time">2015-07-31</div>
                    </div>
                </div>
                </div>

我可以看到article.title,描述等,但是article.user.name是未定义的。如果{{article.user}},它将显示对象。

如何正确打印article.user.name

1 个答案:

答案 0 :(得分:0)

我认为你应该像这样使用安全导航操作符 -

https://fcm.googleapis.com/fcm/send
Content-Type:application/json
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA

{
  "to": "/topics/news",
  "data": {
    "message": "This is a Firebase Cloud Messaging Topic Message!",
   }
}

此链接可为您提供更多详细信息:https://angular.io/docs/ts/latest/guide/template-syntax.html。请参阅“安全导航操作符(?。)和空属性路径”部分

看看这是否有帮助。