angular基礎 指令

2021-10-05 20:53:12 字數 796 閱讀 5212

指令(directive)可以理解為沒有模版的元件,它需要寄宿在乙個元素上——宿主(host)

1.hostbinding 繫結宿主的屬性或樣式

import

from

'@angular/core'

;@directive()

export

class

griditemdirective

2.hostlistener 繫結宿主的事件

import

from

'@angular/core'

;@directive()

export

class

griditemimagedirective

implements

oninit

ngoninit()

:void

private

setstyle

(stylename: string, stylevalue: string | number)

@hostlistener

('click',[

'$event.target'])

handleclick

(ev)

}

3.:host 偽類選擇器

改變宿主元件的css樣式

:host

Angular頁面指令

分為元件帶模板的指令,結構性指令改變宿主文件結構 ngif ngswitch ngfor 屬性性指令改變宿主行為 ngmodel ngstyle ngclass innerhtml 將value作為html標籤來解析 textcontent 將value作為文字解析 ngif ngif 如果vlau...

angular指令總結

ng list ng non bindable ng switch ng readonly ng include ng template angular中有一些不常用,但卻非常有用的指令,如果在開發過程中可以直接使用這些指令,會大大地加快我們的開發效率。ng class 指令用於給 html 元素動...

Angular 指令詳解

1.angular安裝 1.1 因為angular一般是用npm安裝,所以需要先裝npm.npm的安裝一般用nodejs.所以把nodejs裝好,npm也就裝好了。1.2 配置npm的映象,使用國內的映象。npm config set registry 檢查是否設定成功 npm config lis...