It seems that you have to use element[0]
when creating a directive with D3, for example, like below:
app.directive('firstTry', function () {
function link(scope, element, attrs) {
var sampleSVG = d3.select(element[0])
...
So, why element[0]
but not element
? The name element
suggests that it is a single object rather than an array, but apparently that's not the case. Another question: what else does this element
have?
BTW, any official references about this matter would greatly help.
Thank you very much.
As the documentation states, 'replace' determines whether the current element is replaced by the directive. The other option is whether it is just added to as a child basically.
Note: When you create a directive, it is restricted to attribute and elements only by default. In order to create directives that are triggered by class name, you need to use the restrict option. The restrict option is typically set to: 'A' - only matches attribute name.
Directives that want to modify the DOM typically use the
link
option.link
takes a function with the following signature,function link(scope, element, attrs) { ... }
where:
scope
is an Angular scope object.element
is the jqLite-wrapped element that this directive matches.attrs
is a hash object with key-value pairs of normalized attribute names and their corresponding attribute values.
you can find it in documentation here . So to key htmlElement entity - get first member of collection
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With