The AuthService class

This will be our first Angular service; we should be excited!

From Solution Explorer, navigate to the /ClientApp/app/ folder and create a /services/ subfolder within it. Right-click on the new folder and add an auth.service.ts TypeScript file; then, fill it with the following code (relevant lines are highlighted):

import { EventEmitter, Inject, Injectable, PLATFORM_ID } from "@angular/core";import { isPlatformBrowser } from '@angular/common';import { HttpClient, HttpHeaders } from "@angular/common/http";import { Observable } from "rxjs";import 'rxjs/Rx';@Injectable()export class AuthService {    authKey: string = "auth";    clientId: string = "TestMakerFree";    constructor(private http: HttpClient, @Inject(PLATFORM_ID) private ...

Get ASP.NET Core 2 and Angular 5 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.