Câu hỏi phỏng vấn Vue.js
Câu hỏi

Làm thế nào để tạo custom directive?

Câu trả lời

Để tạo một custom directive trong Angular, trước tiên bạn cần hiểu rằng các directive được sử dụng để thao tác với DOM hoặc thêm hành vi tùy chỉnh cho các phần tử HTML.

typescript Copy
import { Directive, ElementRef, Renderer2, HostListener } from '@angular/core';

@Directive({
  selector: '[appCustomDirective]'
})
export class CustomDirective {
  constructor(private el: ElementRef, private renderer: Renderer2) {}

  @HostListener('mouseenter') onMouseEnter() {
    this.changeBackgroundColor('yellow');
  }

  @HostListener('mouseleave') onMouseLeave() {
    this.changeBackgroundColor('white');
  }

  private changeBackgroundColor(color: string) {
    th...
junior

junior

Gợi ý câu hỏi phỏng vấn

middle

Giải thích sự khác biệt giữa one-way data và two-way data trong VueJS?

junior

V-for cần sử dụng key, tại sao? Key hoạt động ra sao?

junior

So sánh setup() với options API.

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào