简体   繁体   English

从Web Api显示数据时出现angular 2错误

[英]angular 2 error while displaying data from web Api

Getting Issue while displaying data in client side getting from API errors are as follows in a Link(please see the links for errors) 在客户端中显示从API错误获取数据时出现问题的链接如下(请查看链接以获取错误)

angular 2.0.0-beta.0 rxjs 5.0.0.beta 角2.0.0-beta.0 rxjs 5.0.0.beta


Error 1 错误1
Error 2 错误2

<div *ngFor="let model of models">
<div class="row">
    <div class="col-md-12">
        <div class="media">
            <div class="media-left">
                <a href="#">
                    <img class="media-object" src="{{model.imageUrl}}" alt="..." style="width:40px; height:40px;">
                </a>
            </div>
            <div class="media-body">
                <h4 class="media-heading">{{model.question}}</h4>

                <p class="text-justify">
                    {{model.answer}}
                </p>
            </div>
        </div>
    </div>
</div>
</div>

In beta / rc versions of Angular2, NgFor is a platform directive so there is nothing to include in your component to be able to use it. 在Angular2的beta / rc版本中, NgFor是一个平台指令,因此您的组件中没有任何可使用它的内容。 So it seems that you use an old version of Angular2 (alpha perhaps) where you needed to include it explicitly: 因此,似乎您使用的是Angular2的旧版本(也许是alpha版本),需要在其中明确包含它:

@Component({
  template: `
    (...)
  `,
  directives: [ NgFor ]
})

If you are using an older version than beta.17 than you need to use # instead of let 如果您使用的是比beta.17更旧的版本, beta.17需要使用#而不是let

Plunker example reproduces the the same error. Plunker示例重现了相同的错误。 Changing let to # fixes it. let更改为#可解决此问题。

There is no need to import FORM_DIRECTIVES or add it to directives since quite some time. 因为已经有一段时间了,所以无需导入FORM_DIRECTIVES或将其添加到指令中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM