[英]Angular: Accessing base element reference for elements with custom directives
Given the following template: 给定以下模板:
<input my-base-directive #someRef> {{someRef.value}}
How do I make someRef
actually reference the HTMLInputelement
rather than my-base-directive
? 如何使
someRef
实际上引用HTMLInputelement
而不是my-base-directive
? I know i can use exportAs
on the directive to make that accessible using the refs, but how do I explicitly not get the directive, and instead get the <input>
element? 我知道我可以在指令上使用
exportAs
以使用refs进行访问,但是我如何显式不获取指令,而获取<input>
元素?
Stackblitz Link: https://stackblitz.com/edit/angular-z6zvbz Stackblitz链接: https ://stackblitz.com/edit/angular-z6zvbz
With this: <input my-base-directive #someRef> {{someRef.value}}
这样:
<input my-base-directive #someRef> {{someRef.value}}
someRef will reference the DOM element the input box. someRef将在输入框中引用DOM元素。
To get to the directive you need to use the 'exportAs' in the directive and use it like this: <input my-base-directive #dir="mybasedir" #someRef [value]="name"> {{someRef.value}}
要转到该指令,您需要在指令中使用'exportAs'并按如下方式使用它:
<input my-base-directive #dir="mybasedir" #someRef [value]="name"> {{someRef.value}}
Check this stackblitz . 检查此stackblitz 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.