1

Using Angular 2+ with wialon remote api

Тема: Using Angular 2+ with wialon remote api

Hello, i want to use wialon remote API from angular http client, but i get the error "from origin 'http://localhost:4200' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource."
this is my code:

import { Component } from '@angular/core';
import 'rxjs/add/operator/map';
import {Http,Response} from "@angular/http";
@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'app';
  private apiUrl ='https://hst-api.wialon.com./wialon/ajax.html?svc=token/login' +
    '&params={"token":"5dce19710a5e26ab8b7b8986cb3c49e58C291791B7F0A7AEB8AFBFCEED7DC03BC48FF5F8"';
  data: any={};

  params:String='} }'
  constructor(private http:Http){
    this.getData();
    this.getUser();
  }

  getData(){
    return this.http.get(this.apiUrl+this.params).map((res:Response)=>res.json());
  }
  getUser(){
    this.getData().subscribe(data=> {
      console.log(data);
      this.data=data;
    })
  }

}

else are there other languages to develop my front end using sdk api
Thank you

2

Using Angular 2+ with wialon remote api

Re: Using Angular 2+ with wialon remote api

Hi Iheb,
this problem supposed to be solved by gurtam side, but they recommend to use wialon.js sdk instead
there is no way to solve it by you, you can install google chrome extension called "CORS" and enable it, it will help you to avoid cors blocked error during developing with your localhost only.
but when you product the apps  to your hosting server, other end-user who will use you application will face the cors problem from their browser
so i recommend you to
try load wialon.js with <script src="wialon.js"> </script> in your index.html and use the library with angular js files code

i did this with react and it's ok.

best regards,
thanks

3

Using Angular 2+ with wialon remote api

Re: Using Angular 2+ with wialon remote api

Hello in my experience for use Angular is recommend use the sdk in the back end, for example I create my own API to my App in this back end (APi) I use the remote api, I was try this method in PHP,Python and Node JS and Work very good.

Regards

4

Using Angular 2+ with wialon remote api

Re: Using Angular 2+ with wialon remote api

iheb.balti
To send requests to wialon you can use wialonjs-api

I has example for Angular 1.3.15 but it's easy to get what's going on
https://github.com/wialon/wialonjs-api/ … index.html