Skip to content

Instantly share code, notes, and snippets.

View lacolaco's full-sized avatar

Suguru Inatomi lacolaco

View GitHub Profile
<div *ngFor="let user of (users$ | async) as users; index as i">
<span>{{ i + 1 }} / users.length</span>
<span>{{ user.name }}</span>
</div>
<div *ngIf="user$ | async as user; else userNotFound">
<p>{{ user.name }}</p>
<p>{{ user.age }}</p>
<img [src]="user.icon">
</div>
<ng-template #userNotFound>
<p>not found</p>
</ng-template>
<div *ngIf="user$ | async as user">
<p>{{ user.name }}</p>
<p>{{ user.age }}</p>
<img [src]="user.icon">
</div>
<div *ngIf="show; then thenBlock; else elseBlock"></div>
<ng-template #thenBlock>show === true</ng-template>
<ng-template #elseBlock>show === false</ng-template>
<div *ngIf="show; else elseBlock">show === true</div>
<ng-template #elseBlock>show === false</ng-template>
@Component({
selector: 'ng-if-then',
template: `
<button (click)="switchPrimary()">Switch Template</button>
<div *ngIf="show; then thenBlock"></div>
<ng-template #primaryBlock>Primary</ng-template>
<ng-template #secondaryBlock>Secondary</ng-template>
`
})
class NgIfThenElse implements OnInit {
<div *ngIf="show; then thenBlock">ignored</div>
<ng-template #thenBlock>show === true</ng-template>
@lacolaco
lacolaco / awesome-counter.js
Last active August 20, 2018 06:59
文化的な最低限度のWeb Component
export class AwesomeCounter extends HTMLElement {
constructor() {
super();
this.attachShadow({mode: 'open'});
this.state = {};
}
connectedCallback() {
this.setState({count: 0});
@lacolaco
lacolaco / oop.md
Created April 10, 2017 05:37
オブジェクト指向について教える

オブジェクト指向プログラミング

  • プログラミングの抽象化に関する精神論
  • 厳密な定義はない
  • いくつかの抽象化の手法をグループ化して名前をつけてあるだけ

カプセル化: Encapusulation

  • ソースコードのフレキシビリティを高めるためのソースコードのデザイン
    • いいデザインにはセンスが必要
    • 鍛える
  • フレキシビリティ
@lacolaco
lacolaco / pseudo-routerLink.ts
Created October 2, 2016 14:23
pseudo-routerlink