I have been working on adding SVG to an Angular2 component's template and I've encountered some challenges. Here is the code snippet I am using:
<object type="image/svg+xml" data="kiwi.svg" class="logo">
Kiwi Logo
</object>
To dynamically add CSS style, I have tried various methods to access the SVG content:
1)
public ngAfterViewInit(): void {
this.el = this._doc.getElementsByTagName('svg');
console.log(this.el);
}
The console displays: [ ]
2)
public ngAfterViewInit(): void {
this.el = this._elementRef.nativeElement.querySelector('object');
console.log(this.el);
}
The console shows: null
My Question:
I need assistance in accessing SVG content and changing CSS styles in TypeScript. Can anyone provide guidance on this matter?