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
#This one-liner removes all cordova installed plugins and then adds them again. | |
#Note: If you are not using Ionic, change 'ionic cordova plugin' to 'cordova plugin' | |
#! /bin/bash | |
cordova plugin list | cut -d ' ' -f 1 | while read plugin; do ionic cordova plugin rm $plugin && ionic cordova plugin add $plugin; done |
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
enum Foo { | |
A = 'a1', B = 'b1', C = 'c1' | |
} | |
// use enum value | |
const finish = (): Partial<{ -readonly [key in Foo]: string }> => { | |
return { [Foo.A]: 'hello'}; // or { 'a1': 'hello' } | |
} | |
// use enum key |
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
<!-- | |
使用[inputlimit], 可以使用默认值。 | |
使用[inputlimit]="2", 可以设置要check的长度。 | |
note that: 不能直接使用 inputlimit或inputlimit="2" 会导致默认值为空或是字符串类型。 | |
--> | |
<input type="text" [inputlimit]="2" formControlName="name" /> |
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'; | |
import { CanActivate } from '@angular/router'; | |
import { tap, delay } from 'rxjs/operators'; | |
import { of } from 'rxjs'; | |
import { SequentialRoutingGuardService } from './sequential-routing-guard.service'; | |
@Injectable({ | |
providedIn: 'root' | |
}) | |
export class Guard1Service implements CanActivate { |
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
// Event Source | |
type propEvent<Type> = { | |
on<Key extends string & keyof Type>( | |
eventName: `${Key}Changed`, | |
callback: (newValue: Type[Key]) => void): void; | |
}; | |
function makeWatchedObject<Type>(obj: Type): Type & propEvent<Type> { | |
const cbMap = new Map<string, Function>(); | |
var proxy = new Proxy({ |
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
interface Person<Type> { | |
id: Type extends "A" ? number : string; | |
name?: string; | |
} | |
/** | |
* a | |
*/ | |
type Category = "A" | "B" |
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
@Directive({ | |
selector: '[formControlName][appAmountMask]' | |
}) | |
export class AmountMaskDirective implements OnInit { | |
private hasFocus = false; | |
private element: HTMLInputElement; | |
private digits = '1.0-7'; |
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
function shallowCopy<T>(origin: T): T { | |
return Object.assign( | |
Object.create(Object.getPrototypeOf(origin)), | |
origin | |
) | |
} | |
function shallowCopy2<T>(origin: T): T { | |
const obj = { ...origin }; | |
Object.setPrototypeOf(obj, (origin as Object).constructor.prototype); |
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, Inject, InjectionToken } from "@angular/core"; | |
import { HttpClient, HttpXhrBackend } from "@angular/common/http"; | |
import { Observable } from "rxjs/Observable"; | |
// import { CUSTOMER_HTTP_CLENT } from "./app.module"; | |
export const CUSTOMER_HTTP_CLENT = new InjectionToken("xx"); | |
@Component({ | |
selector: "my-app", | |
template: ` |
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
ls -r -n -file | foreach{ (cat -encoding UTF8 $_ ) -join "`n" | set-content -encoding UTF8 $_ } |
NewerOlder