Skip to content

Instantly share code, notes, and snippets.

amadousalldotcom

Block or report user

Report or block amadousalldotcom

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View app.component.ts
import { Component } from '@angular/core';
import { TeamService } from './team.service';
import { Team } from './team';
@Component({
selector: 'app-root',
template: `
<h1>Teams</h1>
<ul>
<li *ngFor="let team of teams">{{team.name}}</li>
View team.service.ts
import { Observable } from 'rxjs/Observable';
import { of } from 'rxjs/observable/of';
import { Team } from './team';
const TEAMS: Team[] = [
{id: 1, name: 'FC Barcelona', coach: 'Ernesto Valverde'},
{id: 2, name: 'Toulouse FC', coach: 'Pascal Dupraz'},
{id: 3, name: 'PSG', coach: 'Unaï Emery'}
];
View team.ts
export class Team {
id: number;
name: string;
coach: string;
}
View team.service.ts
import { Observable } from 'rxjs/Observable';
import { Team } from './team';
import { HttpClient } from '@angular/common/http';
export class TeamService {
constructor(private http: HttpClient) {
}
View app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { TeamService } from './team.service';
@NgModule({
declarations: [
AppComponent
View team.service.ts
import { Observable } from 'rxjs/Observable';
import { Team } from './team';
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
@Injectable()
export class TeamService {
constructor(private http: HttpClient) {
}
@amadousalldotcom
amadousalldotcom / mean.pipe.spec.ts
Created Feb 6, 2018
Test suites for the mean pipe
View mean.pipe.spec.ts
import { MeanPipe } from './mean.pipe';
describe('MeanPipe', () => {
const pipe: MeanPipe = new MeanPipe();
it('should create an instance', () => {
expect(pipe).toBeTruthy();
});
describe('Bad Inputs', () => {
@amadousalldotcom
amadousalldotcom / mean.pipe.ts
Created Feb 6, 2018
Transform an array to its mean
View mean.pipe.ts
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'mean'
})
export class MeanPipe implements PipeTransform {
transform(value: number[]): number {
if (!Array.isArray(value)) {
return value;
@amadousalldotcom
amadousalldotcom / mean.pipe.integrated.spec.ts
Last active Feb 7, 2018
Integrated Unit Testing Pipes
View mean.pipe.integrated.spec.ts
import { MeanPipe } from './mean.pipe';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { Component, DebugElement } from '@angular/core';
import { By } from '@angular/platform-browser';
@Component({
template: '<div> {{ values | mean }}</div>'
})
export class MeanPipeHostComponent {
You can’t perform that action at this time.