0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Angular13 開発メモ

Posted at

windowイベントを追加したい

hoge.component.ts
import {
 HostListener
} from '@angular/core';

export class HogeComponent implements OnInit {
  @HostListener("window:scroll",["$event"])
  onWindowScroll(event) {
  }
}

DOMを取得したい

hoge.component.html
<nav #nav></nav>
hoge.component.ts
import {
  ElementRef, ViewChild, AfterViewInit
} from '@angular/core';

export class HogeComponent implements OnInit {
  @ViewChild('nav') nav?: ElementRef;
}

  ngAfterViewInit() {
    //DOMに初期値を設定したい場合はここに記述する
    //this.nav?...
  }
0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?