1
版本: 「angular2」: 「2.0.0-beta.6」Angular2:添加主機動態
我想動態添加新host
上@directive
。
實施例:
@Directive({
selector: '[test]',
host: {
'(mousedown)': '_onmousedown($event)'
}
})
export class TestDirective {
_onmousedown(e){
// Here add a new host dynamically. For example, add a MouseMove listener on the element.
}
}
[1]是否有可能做出這樣的事情而無需直接操縱DOM?
[2]另外,是否可以停止收聽mousedown
?
'ElementRef.nativeElement.addEventListener()'和'Renderer.listen()'有什麼區別? '渲染器'還沒有記錄,你有一些例子鏈接? – plone1
我不是100%確定,但我認爲前者不是webworker/server safe,而後者是(不直接在nativeElement上調用任何東西)。 –