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 { Injectable } from '@angular/core'; | |
@Injectable() | |
export class UserService { | |
user = { | |
name: 'Mannie' | |
}; | |
getUser() { | |
return this.user; |
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 { async, TestBed } from '@angular/core/testing'; | |
import { UserComponent } from './user.component'; | |
import { UserService } from './user.service'; | |
describe('UserComponent', () => { | |
beforeEach(async(() => { | |
TestBed.configureTestingModule({ | |
declarations: [UserComponent] |
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
<p *ngIf="systemError">{{systemErrorMessage}}</p> | |
<div *ngIf="isLoggedIn && !systemError"> | |
<p> | |
{{userDetail.name}} | |
</p> | |
<p>Note: Above user details returned by async call.</p> | |
</div> | |
<div *ngIf="!isLoggedIn && !systemError"> | |
<p> |
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 { UserAsyncService } from './user-async.service'; | |
import { Observable } from 'rxjs'; | |
@Component({ | |
selector: 'app-user-async', | |
templateUrl: './user-async.component.html', | |
styleUrls: ['./user-async.component.scss'], | |
providers: [UserAsyncService] | |
}) |
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 { TestBed, tick, fakeAsync } from '@angular/core/testing'; | |
import { UserAsyncComponent } from './user-async.component'; | |
import { UserAsyncService } from './user-async.service'; | |
import { Observable, Observer } from 'rxjs'; | |
describe('User Async Component:', () => { | |
beforeEach(async () => { | |
TestBed.configureTestingModule({ | |
declarations: [UserAsyncComponent] | |
}); |
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 { Observable, Observer } from 'rxjs'; | |
export class UserAsyncService { | |
user = { name: 'Mannie' }; | |
getUserDetails() { | |
// Create an observables. | |
const userObservables = Observable.create( | |
(observer: Observer<{ name: string }>) => { | |
setTimeout(() => { | |
observer.next(this.user); |
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 { Pipe, PipeTransform } from '@angular/core'; | |
@Pipe({ | |
name: 'reversePipe' | |
}) | |
export class ReversePipe implements PipeTransform { | |
transform(value: any, args?: any): any { | |
return value | |
.split('') | |
.reverse() |
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 { ReversePipe } from './reverse-value.pipe'; | |
// Isolated test case. | |
describe('ReversePipe', () => { | |
it('create an instance', () => { | |
const pipe = new ReversePipe(); | |
expect(pipe).toBeTruthy(); | |
expect(pipe.transform('olleh')).toBe('hello'); | |
}); | |
}); |
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
export interface GoogleData { | |
id: number; | |
country: string; | |
zipCode: string; | |
} |
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 React, { useState } from 'react'; | |
import Person from './Person/Person'; | |
import './App.css'; | |
//class App extends Component { | |
const app = props => { | |
const [personsState,setPersonState] = useState({ | |
persons: [ | |
{name:'mani',age:45}, | |
{name:'papi',age:34} |