title: Error while trying to push the data in observable stream. Angular
body: <p>when i am trying to push data into data stream from    </p>
  
  <p>observable i get error that my observer is undefined. code is below:</p>
  
  <pre><code>@Injectable()
  
  export class CategoryService {
  
  public category:Subject&lt;Category&gt;;
  
  public categories:Observable&lt;Category[]&gt;;
  
  private categoriesObserver:any;
  
    constructor(private authHttpService:AuthHttpService,private authService:AuthService) {
  
  
      this.categories = new Observable(observer=&gt; 
  
      {this.categoriesObserver = observer}).share();
  
  this.category = new BehaviorSubject&lt;Category&gt;(null); }
  
  
  
   getAll() {
  
  
  
     console.log(this.categoriesObserver);
  
      return this.authHttpService
  
      .get('/api/categories', { headers: contentHeaders })
  
      .map((res: Response) =&gt; res.json())
  
      .map((data) =&gt; {
  
  
        var categories = data.map((category) =&gt; {
  
          return new Category(
  
            category._id,
  
            category.name,
  
            category.description,
  
            category.owner,
  
            category.collaborators
  
          );
  
        });
  
  
       this.categoriesObserver.next(categories);
  
  
        return categories;
  </code></pre>
  
  <p>so the app gives an error this.categoriesObserver is undefined.and if i try to define it beforehand i get error that next() is not a function. what can it possibly be? </p>