Skip to content

Instantly share code, notes, and snippets.

View Armenvardanyan95's full-sized avatar

Armen Vardanyan Armenvardanyan95

View GitHub Profile
interface Movie {
id: number;
title: string;
}
@Component({
selector: 'app-some-component-with-form',
template: `...` // our form is here
})
export class SomeComponentWithForm {
interface Movie {
id: number;
title: string;
}
interface User {
firstName: string;
lastName: string;
age: number;
favoriteMovies: Array<Movie | number>;
@Component({
selector: 'app-some-component-with-form',
template: `...` // our form is here
})
export class SomeComponentWithForm {
public form: FormGroup;
public movies: Array<Movie>
constructor(private formBuilder: FormBuilder){
@Component({
selector: 'some-component',
template: `
<div>
<dropdown-component [options]="weightUnits"></dropdown-component>
<-- This will render a dropdown based in the options -->
<input type="text" placeholder="Price">
<dropdown-component [options]="weightUnits"></dropdown-component>
<-- We need to make this one's labels to be preceded with a slash -->
</div>
@Component({
selector: 'some-component',
template: `
<div>
<dropdown-component [options]="weightUnits"></dropdown-component>
<input type="text" placeholder="Price">
<dropdown-component [options]="slashedWeightUnits"></dropdown-component>
<-- Now this one's labels will be preceded with a slash -->
</div>
`
@Component({
selector: 'some-component',
template: `
<div>
<dropdown-component [options]="weightUnits"></dropdown-component>
<input type="text" placeholder="Price">
<dropdown-component [options]="slashedWeightUnits"></dropdown-component>
<-- Now this one's labels will be preceded with a slash -->
</div>
`
@Pipe({
name: 'slashed'
})
export class Slashed implements PipeTransform {
transform(value){
return value.map(item => {
return {
label: '/' + item.label,
value: item.value
};
@Pipe({
name: 'map'
})
export class Mapping implements PipeTransform {
/*
this will be a universal pipe for array mappings. You may add more
type checkings and runtime checkings to make sure it works correctly everywhere
*/
transform(value, mappingFunction: Function){
return mappingFunction(value)
interface User {
fullname: string;
age: number;
createdDate: string | Date;
}
interface Order {
status: 'pending' | 'approved' | 'rejected';
}