Answer the question
In order to leave comments, you need to log in
How to connect your server in Angular 2?
Hello.
Question: I have my own node api server on mongo. I would like to work with it in angular2. I use the framework through the CLI. How can I run it all together?
Answer the question
In order to leave comments, you need to log in
You have an API. You create a service in Angular that will work with this API, i.e. methods that will send requests to your server, receive responses and send them to the front.
An abstract example:
import {Injectable} from "@angular/core";
import {Http} from "@angular/http";
import {Observable} from "rxjs";
interface User {
login: string;
password: string;
}
@Injectable()
export class ApiService {
constructor(private _http: Http) {
}
getUsers(): Observable<User[]> {
return this._http.get('url к вашему api').map(result => result.json());
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question