收到来自 api 的信息,页面上没有结果 {{value_expression}}
Info from api received, no result on the page by {{value_expression}}
您好,先谢谢您,
我有一个关于{{ value_expression }}的问题。我将 运行 一个使用 Drupal 9 中的 REST api 的小应用程序。我的列表组件工作正常,但是当我进一步单击我的详细信息页面时,我不会收到任何信息,但是当我使用 {{ object|json }} 它正在输出全部(与硬币相关 url,参见示例)api,因此它正在接收其数据。
我用的是:
- Angular 10
- Drupal 9
示例json 管道{{ ico | json}}
[ { "title": "Coin", "body": "<p>This is just the description about the Coin project</p>\r\n", "field_coin_uri": "name-of-coin", "field_coin_symbol": "SYMB" } ]
Data.service.ts:
getIcoDetail(field_coin_uri: string) : Observable<Icos> {
const url = `${this.ApiUrl}/coins/${field_coin_uri}`;
return this.http.get<Icos>(url);
}
detail.component.ts:
export class IcoDetailComponent implements OnInit {
ico: Icos;
constructor(
private route: ActivatedRoute,
private dataService: dataService
) { }
ngOnInit() {
const field_coin_uri = this.route.snapshot.paramMap.get('field_coin_uri');
console.log(field_coin_uri);
this.dataService.getIcoDetail(field_coin_uri).subscribe( ico => this.ico = ico );
}
}
detail.component.html
<div *ngIf="ico">
{{ ico|json }}
<h3>{{ ico.title }}</h3>
<p>{{ ico.body }}</p>
</div>
如果回答我的问题需要任何信息,请告诉我,我会提供给你。
您从 API 收到的信息是一个数组。您需要使用索引值访问它并检查以下是否有效。
this.dataService.getIcoDetail(field_coin_uri).subscribe( ico => this.ico = ico[0] );
您好,先谢谢您,
我有一个关于{{ value_expression }}的问题。我将 运行 一个使用 Drupal 9 中的 REST api 的小应用程序。我的列表组件工作正常,但是当我进一步单击我的详细信息页面时,我不会收到任何信息,但是当我使用 {{ object|json }} 它正在输出全部(与硬币相关 url,参见示例)api,因此它正在接收其数据。
我用的是:
- Angular 10
- Drupal 9
示例json 管道{{ ico | json}}
[ { "title": "Coin", "body": "<p>This is just the description about the Coin project</p>\r\n", "field_coin_uri": "name-of-coin", "field_coin_symbol": "SYMB" } ]
Data.service.ts:
getIcoDetail(field_coin_uri: string) : Observable<Icos> {
const url = `${this.ApiUrl}/coins/${field_coin_uri}`;
return this.http.get<Icos>(url);
}
detail.component.ts:
export class IcoDetailComponent implements OnInit {
ico: Icos;
constructor(
private route: ActivatedRoute,
private dataService: dataService
) { }
ngOnInit() {
const field_coin_uri = this.route.snapshot.paramMap.get('field_coin_uri');
console.log(field_coin_uri);
this.dataService.getIcoDetail(field_coin_uri).subscribe( ico => this.ico = ico );
}
}
detail.component.html
<div *ngIf="ico">
{{ ico|json }}
<h3>{{ ico.title }}</h3>
<p>{{ ico.body }}</p>
</div>
如果回答我的问题需要任何信息,请告诉我,我会提供给你。
您从 API 收到的信息是一个数组。您需要使用索引值访问它并检查以下是否有效。
this.dataService.getIcoDetail(field_coin_uri).subscribe( ico => this.ico = ico[0] );