Martin
Martin

Reputation: 557

Subscribing to BehaviorSubject throws error in Angular 8

Working on a Single Page Application in Angular 8 whereby am parsing some data from a component to a service, then in the service I subscribe to it using rxjs BehaviorSubject.on compilation on Angular CLI I get this error src/app/Services/shared.service.ts(12,21): error TS2554: Expected 1 arguments, but got 0.

Cant seem to locate what the issue is?

shared service

import { Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs';
import { TokenService } from './token.service';

@Injectable({
  providedIn: 'root'
})

export class SharedService {

    //All children
    private children = new BehaviorSubject;
    checkAll$ = this.children.asObservable();

    childData(data:any){
       this.children.next(data);
    }

    constructor(private Token : TokenService) { }
}

Upvotes: 0

Views: 1131

Answers (1)

zmag
zmag

Reputation: 8251

BehaviorSubject needs an argument. You didn't provide it.

private children = new BehaviorSubject(null);

Upvotes: 1

Related Questions