Created
May 5, 2020 20:46
-
-
Save manoj-choudhari-git/91064b2cab7f53b951874b8c549f2b00 to your computer and use it in GitHub Desktop.
App component for Angular App, calling web API on ngOnInit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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