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
/* | |
*ngFor="let c of oneDimArray | sortBy:'asc'" | |
*ngFor="let c of arrayOfObjects | sortBy:'asc':'propertyName'" | |
*/ | |
import { Pipe, PipeTransform } from '@angular/core'; | |
import { orderBy } from 'lodash'; | |
@Pipe({ name: 'sortBy' }) | |
export class SortByPipe implements PipeTransform { |
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
<!-- const cars=['Audi','Merc','BMW','Volvo','Tesla'] --> | |
<ul> | |
<li *ngFor="let car of cars">{{car}}</li> | |
</ul> |
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
const reMapAll=(custom_schema,missingKeys,data:any)=>{ | |
const newArray=[] | |
for(let d of data){ | |
newArray.push(createObject(custom_schema,missingKeys,d)); | |
} | |
return newArray; | |
} |
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
const createObject=(custom_schema,missingKeys,data)=>{ | |
const newObj=Object.create({}); | |
// add available keys | |
for(let key of Object.keys(custom_schema)){ | |
const k=custom_schema[key]; | |
newObj[k]=data[key]; | |
} | |
// add missing keys | |
for(let k of missingKeys){ | |
newObj[k]=''; |
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
// array | |
const data=[ | |
{pid:1000,pname:'test',pimg:'demo',pCat:'123'}, | |
{pid:1001,pname:'test 1',pimg:'demo 1',pCat:'123'}, | |
{pid:1002,pname:'test 2',pimg:'demo 2',pCat:'123'}, | |
]; | |
// single object | |
const data={pid:1000,pname:'test',pimg:'demo',pCat:'123'} |
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
const product=['productId','productName','productStock','productImage','productCost']; |
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
const schema={pid:'productId',pname:'productName',pimg:'productImage',pCat:'productCategory'}; |
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
// using lodash library | |
const reMap=(custom_schema,conversion_schema,data)=>{ | |
const actualKeys=conversion_schema; | |
const availableKeys=_.values(custom_schema); | |
const missingKeys=_.difference(actualKeys,availableKeys); | |
if(!_.isArray(data)) | |
return createObject(custom_schema,missingKeys,data); | |
else | |
return reMapAll(custom_schema,missingKeys,data); | |
} |
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 { Directive } from '@angular/core'; | |
import { NG_VALIDATORS } from '@angular/forms'; | |
import { zipCodeValidator } from '../forms/validators'; | |
@Directive({ | |
selector: '[appZipCode][ngModel]', | |
providers: [ | |
{ | |
provide: NG_VALIDATORS, | |
useValue: zipCodeValidator, | |
multi: true |
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
<div *ngIf="addressObj.get('pincode').touched"> | |
<small *ngIf="addressObj.get('pincode').hasError('required')">Pincode is required</small> | |
<small *ngIf="addressObj.get('pincode').hasError('zipCode')"> | |
allowed pincode is {{addressObj.get('pincode').getError('zipCode').validCode}} | |
</small> | |
</div> |