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
@Component({ /* ... */ }) | |
export class SomeComponent { | |
// streamifies input | |
@Input$() prop: Observable<string>; | |
// lifecycle notifier as an Observable stream | |
@OnDestroy$() destroy$: Obseravble<void>; | |
// lifecycle hook as decorator instead of implements interface |
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 { OverlayContainer } from '@angular/cdk/overlay'; | |
export class AppComponent implements OnInit { | |
// use this to set correct theme class on app holder | |
// eg: <div [class]="themeClass">...</div> | |
themeClass: string; | |
constructor( | |
private overlayContainer: OverlayContainer |
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 is then built as Angualr element | |
with | |
ngDoBootstrap() { | |
const ElementExample = createCustomElement(ElementExampleComponent, { injector: this.injector }); | |
customElements.define('element-example', ElementExample); | |
} |
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 '~@angular/material/theming'; | |
// always include only once per project | |
@include mat-core(); | |
// import our custom themes | |
@import 'my-theme.scss'; | |
@import 'my-light-theme.scss'; | |
@import 'my-dark-theme.scss'; |
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 '~@angular/material/theming'; | |
// always include only once per project | |
@include mat-core(); | |
// import our custom theme | |
@import 'my-theme.scss'; | |
// specify theme class eg: <body class="my-theme"> ... </body> | |
.my-theme { |
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
// define 3 theme color | |
// mat-palette accepts $palette-name, main, lighter and darker variants | |
$my-theme-primary: mat-palette($mat-indigo, 700, 300, 900); | |
$my-theme-accent: mat-palette($mat-light-blue); | |
$my-theme-warn: mat-palette($mat-deep-orange, A200); | |
// create theme (use mat-dark-theme for themes with dark backgrounds) | |
$my-theme: mat-light-theme( | |
$my-theme-primary, | |
$my-theme-accent, |
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 function cancelable() : MethodDecorator { | |
return function ( target : any, propertyKey : string, descriptor : PropertyDescriptor ) { | |
const originalFn = descriptor.value; | |
const subject = new BehaviorSubject(undefined); | |
const result$ = subject.asObservable().switchMap(args => originalFn(...args)); | |
descriptor.value = (...args) => { | |
subject.next(args); |
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 class AuthApplicationService { | |
// inject all needed services | |
constructor( | |
private sessionService: SessionService, | |
private authService: AuthService | |
) {} | |
// orchestrate multi service execution | |
// note that subscription and cancelation are responsibility of the caller |
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
@Injectable() | |
export class TodosService { | |
private model: Model<Todo[]>; | |
todos$: Observable<Todo[]>; | |
constructor(private modelFactory: ModelFactory<Todo[]>) { | |
this.model = this.modelFactory.create([]); | |
this.todos$ = this.model.data$; |
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 { NgModule } from '@angular/core'; | |
import { MODEL_PROVIDER } from './model.service'; | |
@NgModule({ | |
/* ... */ | |
providers: [MODEL_PROVIDER] | |
}) | |
export class CoreModule { } |
NewerOlder