Tutorial by Examples

services/my.service.ts import { Injectable } from '@angular/core'; @Injectable() export class MyService { data: any = [1, 2, 3]; getData() { return this.data; } } The service provider registration in the bootstrap method will make the service available globally. main.ts im...
services/my.service.ts import { Injectable } from '@angular/core'; @Injectable() export class MyService { data: any = [1, 2, 3]; getData() { return Promise.resolve(this.data); } } getData() now acts likes a REST call that creates a Promise, which gets resolved imme...
Given a service that can login a user: import 'rxjs/add/operator/toPromise'; import { Http } from '@angular/http'; import { Injectable } from '@angular/core'; interface LoginCredentials { password: string; user: string; } @Injectable() export class AuthService { constructor(pri...

Page 1 of 1