gpt4 book ai didi

angular - 如何以 Angular 显示表单内的对象值?

转载 作者:行者123 更新时间:2023-12-02 10:12:15 24 4
gpt4 key购买 nike

我想将 json 对象的单个值显示为 Angular 形式。如何做到这一点?

输出

{
"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)

}

收到此错误:

Argument of type 'Response' is not assignable to parameter of type 'string'.

最佳答案

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

在模块中导入 HttpClientmodule

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

@NgModule({
imports: [
HttpClientModule,
],

service.ts 的更改

   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;
})
}

在您的代码中,您使用的数组也会导致问题

关于angular - 如何以 Angular 显示表单内的对象值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50266560/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com