I'm a little confused at the moment and could use some guidance. My goal is to dynamically insert the current date into an API URL using Angular. Here is the progress I have made so far:
Below is my Typescript code:
import { HttpClient} from '@angular/common/http';
import { DatePipe } from '@angular/common';
@Component({
selector: 'app-matches',
templateUrl: './matches.component.html',
styleUrls: ['./matches.component.css']
})
export class MatchesComponent implements OnInit {
public myMatches: any = []
myDate = new Date();
constructor( private http: HttpClient , public datePipe: DatePipe) {
let myDates = this.datePipe.transform(this.myDate, 'yyyy-MM-dd');
}
getMyMatches(){
const url = "https://app.sportdataapi.com/api/v1/soccer/matches?apikey=myKey&season_id=1980&date_from=+myDates"
return this.http.get(url).subscribe((res)=>{
this.myMatches =res
console.log(res);
})
}
ngOnInit(): void {
this.getMyMatches()
}
}
In my web browser's console, I am receiving a 500 response status error. The DatePipe has been included in the app module's providers.