This file contains hidden or 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
| export class AppError { | |
| constructor(public error?: any) { } | |
| } |
This file contains hidden or 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 '../services/auth.service' | |
| import { Router } from '@angular/router' | |
| @Component({ | |
| selector: 'app-login', | |
| templateUrl: './login.component.html', | |
| styleUrls: ['./login.component.css'] | |
| }) | |
| export class LoginComponent implements OnInit { |
This file contains hidden or 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 { Injectable } from '@angular/core' | |
| import { HttpClient, HttpErrorResponse } from '@angular/common/http' | |
| import { tap, catchError } from 'rxjs/operators' | |
| import { throwError } from 'rxjs' | |
| @Injectable({ | |
| providedIn: 'root' | |
| }) | |
| export class AuthService { |
This file contains hidden or 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 { Router } from '@angular/router' | |
| import { tap, catchError } from 'rxjs/operators' | |
| import { throwError } from 'rxjs' | |
| @Component({ | |
| selector: 'app-login', | |
| templateUrl: './login.component.html', | |
| styleUrls: ['./login.component.css'] | |
| }) |
This file contains hidden or 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 { InMemoryDbService } from 'angular-in-memory-web-api' | |
| import { RequestInfo } from 'angular-in-memory-web-api/interfaces' | |
| export class MyInMemoryService implements InMemoryDbService { | |
| createDb() { | |
| // same as before | |
| } | |
| // HTTP POST interceptor |
This file contains hidden or 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
| @Injectable() | |
| export class CustomersService { | |
| constructor( | |
| private http: Http) { } | |
| getAll() { | |
| return this.http.get('api/customers') | |
| .subscribe(customers => { | |
| console.log(customers) |
This file contains hidden or 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 { InMemoryDbService } from 'angular-in-memory-web-api'; | |
| import { RequestInfo } from 'angular-in-memory-web-api/interfaces'; | |
| export class MyInMemoryService implements InMemoryDbService { | |
| // In-Memory DB will intercept /api/whatever calls and return data | |
| createDb() { | |
| const customers = [ | |
| { id: 1, username: 'fred92', password: '1234' }, | |
| { id: 2, username: 'john69', password: 'abcd' }, |
This file contains hidden or 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 { HttpClientModule } from '@angular/common/http' | |
| import { HttpClientInMemoryWebApiModule } from 'angular-in-memory-web-api' | |
| import { MyInMemoryService } from './services/my-in-memory.service' | |
| @NgModule({ | |
| imports: [ | |
| HttpClientModule, | |
| // import HttpClientInMemoryWebApiModule after HttpClientModule | |
| HttpClientInMemoryWebApiModule.forRoot(MyInMemoryService) | |
| ] |
This file contains hidden or 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
| function closestEnemy(matrix) { | |
| let length = matrix.length | |
| let isValid = matrix.some(v => v.includes(2)) | |
| if (!isValid) return -1 | |
| let startingPoint | |
This file contains hidden or 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
| function isValid(string) { | |
| let v = 0 | |
| let h = 0 | |
| for (let char of string) { | |
| if (char === 'd') v++ | |
| if (char === 'u') v-- | |
| if (char === 'r') h++ |