Ncir Hichem
Ncir Hichem

Reputation: 3

How to make http.get() request to node.js from angular?

I'm trying to http.get() request to node.js from angular in institute.ts.

import {Http} from "@angular/http";
export class InstituteListPage {
  data: any =[];
  constructor(private http:Http) {
  this.getData();
  }
getData(){
        let URL = "http//localhost:3005/institute";
        console.log(URL);
       this.http.get(URL).subscribe(data => { console.log("****************"   ,data)},
          err => {
            let alert = this.AlertC.create(
              {
                title:"ERROR",
                message:err,
                buttons: [
                  {
                    text:"OK",
                    role:"cancel"
                
                  }
                ]
              }
            );
            alert.present();
          })
          
  }
  }

When I run this code, I get

GET http://localhost:8100/http//localhost:3005/institute 404 (Not Found)

while the http post request works fine

How can I get it done?

Upvotes: 0

Views: 310

Answers (1)

Demarsch
Demarsch

Reputation: 1479

Most likely the issue here is misspelled schema in your URL. It should be http:// otherwise this URL will be (and actually is) treated by Angular as a relative one

Upvotes: 1

Related Questions