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 { 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
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 { 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 { Pipe, PipeTransform } from '@angular/core'; | |
@Pipe({ name: 'excerpt' }) | |
export class ExcerptPipe implements PipeTransform { | |
transform(text: string, limit: number = 5) { | |
if (text.length <= limit) { | |
return text; | |
} | |
return text.substring(0, limit) + '...'; | |
} |
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
// Animal factory | |
const Animal = function(name){ | |
const animal = {}; | |
animal.name = name; | |
animal.walk = function(){ | |
console.log(this.name + " walks"); | |
} | |
return animal; | |
}; |
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
// Using slice() to Remove value from beginning and end of string. | |
sliceString = function (value) { | |
let result = value.slice(1, -1); | |
return result; | |
} | |
// Using splice() method to changes the contents of an array by removing | |
// or replacing existing elements and/or adding new elements | |
var months = ['Jan', 'March', 'April', 'June']; |
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
//emit value every 1s | |
const source = interval(1000); | |
const example = source.pipe( | |
map(val => { | |
if (val > 5) { | |
//error will be picked up by retryWhen | |
throw val; | |
} | |
return val; | |
}), |
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
(focus)="myMethod()" // An element has received focus | |
(blur)="myMethod()" // An element has lost focus | |
(submit)="myMethod()" // A submit button has been pressed | |
(scroll)="myMethod()" | |
(cut)="myMethod()" | |
(copy)="myMethod()" | |
(paste)="myMethod()" |
OlderNewer