Note that setAttribute
only takes strings since attributes are strings, but DOM elements can have non-string properties. See also: What is the difference between properties and attributes in HTML?
Inspect the custom element and notice that it actually is a combination of HTMLElement
(NgElement
more specifically) and your component class:
console.dir(document.querySelector('some-custom-element'));
So, as soon as you locate the DOM element, you already directly have the instance of your component! Then you can directly access the object and set properties on it like this:
import {FooElement} from '...';
const myElement = document.querySelector('some-custom-element')! as HTMLElement & FooElement;
// Number instead of string!
myElement.foo = 5;
That would work with this example Angular Element:
@Component({
...
})
export class FooElement {
@Input() foo = 0;
}
At least this works with the component's properties. I haven't tested if methods are also exposed and I'm not sure how EventEmitters work in Elements.