Skip to content

Instantly share code, notes, and snippets.

@manoj-choudhari-git
Created May 5, 2020 20:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manoj-choudhari-git/91064b2cab7f53b951874b8c549f2b00 to your computer and use it in GitHub Desktop.
Save manoj-choudhari-git/91064b2cab7f53b951874b8c549f2b00 to your computer and use it in GitHub Desktop.
App component for Angular App, calling web API on ngOnInit
import { Component, OnInit } from '@angular/core';
import { AuthService } from './auth.service';
import { HttpClient } from '@angular/common/http';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
title = 'SecureApp';
constructor(private authService: AuthService, private http: HttpClient) { }
ngOnInit() {
this.authService.initializeAuth();
let endpoint = "https://localhost:44389/weatherforecast";
this.http.get(endpoint).toPromise()
.then(data => {
console.log(data);
alert(JSON.stringify(data));
});
}
login() {
this.authService.logIn();
}
logOut() {
this.authService.logOut();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment