Just joined this platform and diving into Angular 7 coding, but already facing an issue.
I've set up two components along with a service. The data is fetched by the service upon clicking a button in the searchbar
component, and I aim to display it in the search-res
view.
The service has to extract data from the searchbar
component.
Check out the service code below:
import { Injectable } from '@angular/core';
import { HttpClient } from '@common/http'
import { Observable } from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class DataService {
constructor(private http:HttpClient) { }
getData( input:string ):Observable<any>
{
return this.http.get<any>('https://newsapi.org/v2/everything?q='+input+'&apiKey=b9d34afdf37948cda401c3dc0afe1189')
}
}
I'm uncertain about how to proceed in these components:
import { Component, OnInit } from '@angular/core';
import { DataService } from '../data.service';
@Component({
selector: 'app-searchbar',
templateUrl: './searchbar.component.html',
styleUrls: ['./searchbar.component.css']
})
export class SearchbarComponent implements OnInit {
public inData : string ;
constructor(private data : DataService) { }
ngOnInit() {
}
}
search-res component
import { Component, OnInit } from '@angular/core';
import { DataService } from '../data.service';
@Component({
selector: 'app-search-res',
templateUrl: './search-res.component.html',
styleUrls: ['./search-res.component.css']
})
export class SearchResComponent implements OnInit {
constructor(private data: DataService) { }
ngOnInit() {
}
}
Any assistance would be greatly appreciated!