【发布时间】:2021-02-06 14:22:21
【问题描述】:
我使用新闻 api 制作新闻应用程序,并且我正确地获取数据,但没有将数据从服务发送到组件,那么如何将数据从服务发送到组件
并通过 rxjs 组件到组件
import { Injectable } from '@angular/core';
import { Subject } from 'rxjs';
@Injectable()
export class NewService {
private pushSource = new Subject<object>();
Country_Name;
constructor(private http:HttpClient,) {
this.messages$ = this.pushSource.asObservable()
} // define function for call the category
categoryNews(category)
{
var categoryData = this.http.get(`https://newsapi.org/v2/top-headlines?country=in&category=${category}&apiKey=********`)
.subscribe(Data=> this.pushSource.next(Data));
}
news(t_h)
{
console.log(t_h);
this.pushSource.next(t_h);
} }
【问题讨论】:
标签: node.js angular typescript