I checked all the other Posts here with a similar Problem but I was not able to find a fitting solution.
I went to the Angular Docs to follow this post https://angular.io/tutorial/toh-pt4 and while I did all like described in there I get the error TypeError: Cannot read property 'subscribe' of undefined
posts.service.ts
import { Injectable } from '@angular/core';
import { Observable, of } from 'rxjs';
var Prismic = require('prismic-javascript');
const apiEndpoint = "https://hehypfgdgees3124312424heetyh.edn.prismic.io/api/v2"
@Injectable({
providedIn: 'root'
})
export class PostsService {
constructor() { }
getPosts(): Observable<[]> {
Prismic.getApi(apiEndpoint).then(api => {
return of(api.query(""));
})
return
}
}
and my Component landingpage.component.ts
import { Component, OnInit } from '@angular/core';
import { PostPreview } from '../../types/PostPreview';
import { PostsService } from '../../services/posts.service';
import { Observable } from 'rxjs'
@Component({
selector: 'app-landingpage',
templateUrl: './landingpage.component.html',
styleUrls: ['./landingpage.component.scss']
})
export class LandingpageComponent implements OnInit {
examplePreview: PostPreview
exampleNewsfeed: Array<{}>
constructor(private postService: PostsService) { }
ngOnInit() {
this.examplePreview = {
titel: 'Hello',
subtitel: 'Subtitel',
backgroundImageUrl: 'https://www.welt.de/img/politik/deutschland/mobile191563833/0437936357-coriginal-w780/Forderungen-von-Fridays-For-Future-vorgestellt-3.jpg',
abgedunkelt: true
};
this.postService.getPosts().subscribe(posts => this.exampleNewsfeed = posts);
}
}
My goal is to get the results of that API call into my component when subscribing tot he function. Thanks in advance.