Abonnieren ist nicht ein Fehler einer Funktion

Ich versuche zu abonnieren, um eine observable, die von einem Dienst, baut es ohne Fehler aber ich bekomme die Fehlermeldung "diese.service.getBanners(...).abonnieren ist nicht eine Funktion" beim anzeigen im browser.

Service:

import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';

@Injectable()

export class BannerService {

    banners: any = ['1','2','3'];

    constructor(
    ) {}

    getBanners(): Observable<any[]> {
        return this.banners;
    }

    setBanners(banners: any[]): void {
        this.banners = banners;
    }

}

Komponente:

import { Component, ViewEncapsulation, OnInit } from '@angular/core';
import { Observable } from 'rxjs';
import { BannerService } from './../banner/banner.service';

@Component({
    selector: '.banner',
    templateUrl: './banner.component.html',
    styleUrls: ['./banner.component.sass'],
    encapsulation: ViewEncapsulation.None
})

export class BannerComponent implements OnInit {

    banners: any[];

    constructor(private bannerService: BannerService){

    }

    ngOnInit() {
        this.bannerService.getBanners().subscribe(banners => this.banners = banners);
    }
}

Irgendwelche Ideen was ich falsch mache?

InformationsquelleAutor Steve | 2017-08-15

Schreibe einen Kommentar