Angular 8 Observable Returns "_isScalar:false..."

Joe Berthelot

Just trying to simply display the contents of a JSON object from a GET request.

Service:

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

@Injectable()
export class LightsService {

  constructor(private http: HttpClient) {}

  fetchLights(): Observable<Object> {
    const URL = 'http://****/api/S97t-zlmOCIeKXxQzU66WxWLY2z6oKenpLM95Uvt/lights';
    console.log('Service');
    return this.http.get(URL);
  }
}

Component:

import { Component } from '@angular/core';
import { LightsService } from './lights.service';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.less']
})
export class AppComponent {
  lights;
  constructor(private lightsService: LightsService) {}

  fetchLights() {
    console.log('Component');
    this.lights = this.lightsService.fetchLights();
    console.log(this.lights);
  }
}

HTML:

<button (click)="fetchLights()">Fetch Lights</button>

<ul>
  <li *ngFor="let light of lights | keyvalue">{{light.key}}:{{light.value}}</li>
</ul>

I'd prefer to not have to use the 'keyvalue' pipe but it seems to be the only way to get anything returned at all, however here is a screenshot of what gets returned when the function is called:

enter image description here

Gilsdav

An observable can not be used as a value.

You have to use the pipe async to get the value of an observable.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Angular 4 Service method returns always undefined instead Observable

Angular 5 navigation cancelled after guard returns Observable

Angular6 Get method response "_isScalar":false,"source"

Angular 2 and RxJS: How to change HTTP call that returns Observable

How to let Angular 6 Http Get method returns an array of observable instead of an observable of array?

Angular 8 : observable.pipe() not working anymore?

Angular 8 getting the value of a BehaviorSubject returns null

Angular 8 subscribe to an observable in an interceptor

Facing problem in Subscribing Observable to component in Angular 8

Angular 8 and setting observable inside subscription

Angular 8 return observable after chain of async calls

Angular 8 Observable get data in data.all

Get Last Value from Observable in Angular 8

Angular 8: Property 'of' does not exist on type 'typeof Observable'

Angular subscription on observable returns undefined

angular 4 observable returns [object Object]

Storing observable data into global variable returns 'undefined' in Angular 4

RXJS in Angular 6 returns only { "_isScalar": false }

Angular 7 - Accessing to service returns undefined in observable

How to use Observable.fromPromise in Angular 8?

How to solve catch error in Observable in angular 8?

Cant get data from observable in other component Angular 8

Angular 8 return Observable<boolean> from function

Angular 8 @viewChild - returns undefined

Observable property displaying null in Angular 8

Observable & Observer in Angular 8

How to get _value from `Observable {_isScalar: false, source: BehaviorSubject}`

Trying to Subscribe to a method that returns an Observable in Angular

Angular BehaviorSubject observable returns null