I have request like this:
import {Component, OnInit} from '@angular/core';
import { Http, Response } from '@angular/http';
import {Observable} from 'rxjs';
import 'rxjs/add/operator/map';
import {isNode} from 'angular2-universal';
@Component({
selector: 'app-todo',
templateUrl: './todo.component.html',
styleUrls: ['./todo.component.css']
})
export class TodoComponent implements OnInit {
constructor(private http: Http) {}
private todo: any;
ngOnInit() {
if(isNode) {
this.http
.get('http://api.pushsc.com/api/v1/code/show/589ceab40a58d602a0b99d10')
.map((response: Response) => response.json())
.subscribe(data => {
console.log(data);
this.todo = data;
})
error => {
console.log(error);
};
}
}
}
In console I get response from API which mean http from server works... But poroblem is on client even if I remove isNode content from http not render as it should... What can be a problem?
From the source code of angular2-universal from this link
By default the value assigned to the
isNodeis true and so your http call fails if it is not available.