如何以角度显示表单内的对象值?

里娜

我想将json对象的单个值显示为有角度的形式。怎么做?

输出

{
  "Order": {
    "active": true,
    "Orders_Entrydate": "2017-12-31T18:30:00.000Z",
    "LastTouchDateTime": "2018-05-10T05:46:38.702Z",
    "_id": "5af07544eb26f918e0e2ff74",
    "Orders_Name": "Test1",
    "Orders_Number": "1011",
    "Orders_LoanNumber": 1328,
    "Orders_PropertyAddress1": "test address1",
    "Orders_PropertyAddress2": "test address 1",
    "Orders_PropertyCity": "testCity",
    "Orders_Propertyzipecode": 1236,
    "Orders_Countyfee": 500,
    "Orders_Additionalfee": 100,
    "Orders_Customerpricing": 150
  }
}

view-order.ts

export class countyViewOrderComponent implements OnInit {
  orders: any[];

  constructor(private orderService: countyvieworder, private router: Router, private cookie_service: CookieService) {

  }
  getorder() {
    this.orderService.getOrders().subscribe(response => {
      this.orders = response.json();


    })
  }


  onSelect(selectedItem: any) {
    this.cookie_service.put('key', selectedItem._id)
    // this.cookie_service.get('key')
    this.router.navigate(['pages/home/County/orderEntrybyCounty']);


  }



  ngOnInit() {

    this.getorder()


  }


}

getOrderbyOrderNo()服务

getOrderbyOrderNo() {
        this.id = this.cookie_service.get('key');
        return this.http.get('http://localhost:8080/View/'+ this.id)

    }

收到此错误:

“响应”类型的参数不能分配给“字符串”类型的参数。

普兰尼·拉娜(Pranay Rana)

建议您利用HttpClient,它将为您进行对话。HTTPClient是Angular中的新模块,它取代了旧的HTTP。

导入HttpClientmodule模块

import { HttpClientModule } from '@angular/common/http';

@NgModule({
  imports: [
    HttpClientModule,
  ],

服务变更

   import { HttpClient } from '@angular/common/http';
  constructor(private httpClient: HttpClient) { }

  getOrderbyOrderNo() :Observable<any> {
        this.id = this.cookie_service.get('key');
        return this.httpClient.get('http://localhost:8080/View/'+ this.id)
    } 

view-order.ts

 order: any;//no array as you are expecting only one element 
 getorder() {
    this.orderService.getOrders().subscribe(response => {
      this.order = response;
    })
  }

在您的代码中,您正在使用也会引起问题的数组

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章