Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 5,在html中显示json_Html_Angular_Typescript - Fatal编程技术网

Angular 5,在html中显示json

Angular 5,在html中显示json,html,angular,typescript,Html,Angular,Typescript,在Angular 5中的项目中,我想在HTML代码中显示参数“default\u price”:100,但我的代码显示所有default\u price 组件。ts this.ws.getAllProduct().subscribe( products => { this.products = products.map((product) => { return new Product(product); })

在Angular 5中的项目中,我想在HTML代码中显示参数
“default\u price”:100
,但我的代码显示所有default\u price

组件。ts

   this.ws.getAllProduct().subscribe(
      products => {
          this.products = products.map((product) => {
          return new Product(product);
        });
      }
    );
component.html

  <div class="row">
    <div class="input-field col s12">
      <label for="unit_price" *ngFor="let item of products">{{item.default_price}}</label>
      <input formControlName="unit_price" id="unit_price" type="number" class="validate" placeholder="unit_price">
    </div>
  </div>
我只想在html代码中显示“产品id”:“4”,“产品名称”:“产品4”


你能给我一些建议吗?

你不需要ngFor如果你需要显示特定的对象,你可以使用array.find()从你的json产品中查找数组中的特定元素。StatusDescription是数组

this.ws.getAllProduct().subscribe(products=>{return this.products.find(x=>x.product_name==='Product4')[3];});});------>TypeError:无法读取未定义的属性“find”。你能帮帮我吗?那么产品不是数组
{
    "StatusCode": 0, "StatusMessage": "OK", "StatusDescription":
    [
        {
            "product_id": "1",
            "product_name": "Product1",
            "description": "Product1",
            "default_price": 50,
            "lastmoduserid": "31",
            "lastmoddtm": "2018-02-06T13:26:17.000Z",
            "active": 1
        },
        {
            "product_id": "2",
            "product_name": "Product2",
            "description": "Product2",
            "default_price": 60,
            "lastmoduserid": "31",
            "lastmoddtm": "2018-02-06T13:35:17.000Z",
            "active": 1
        },
        {
            "product_id": "3",
            "product_name": "Product3",
            "description": "Product3",
            "default_price": 80,
            "lastmoduserid": "31",
            "lastmoddtm": "2018-02-06T13:35:22.000Z",
            "active": 1
        },
        {
            "product_id": "4",
            "product_name": "Product4",
            "description": "Product4",
            "default_price": 100,
            "lastmoduserid": "31",
            "lastmoddtm": "2018-02-06T13:25:54.000Z",
            "active": 1
        },
        {
            "product_id": "5",
            "product_name": "Product5",
            "description": "Product5",
            "default_price": 120,
            "lastmoduserid": "31",
            "lastmoddtm": "2018-02-06T13:35:27.000Z",
            "active": 1
        }
    ]
}