Exploring Angular development has been quite a challenge for me. I've heard that typescript is an extension of javascript, but when it comes to manipulating HTML elements in the .ts file, I seem to be at a loss.
I attempted a simple document.getElementById
function, only to find myself stuck on how to make it work in typescript...
In my component's html file, I placed a <p>
element with an assigned id
. Now, from the typescript side, I'm struggling to update its innerHTML. Can someone shed some light on how this can be accomplished in typescript?
The code snippet below is what I tried, unfortunately without success:
import { Component, OnInit } from '@angular/core';
import { DOCUMENT } from '@angular/common';
const myContainer = document.getElementById('test') as HTMLInputElement;
myContainer.value = 'Hello from about';
@Component({
selector: 'app-about',
templateUrl: './about.component.html',
styleUrls: ['./about.component.css']
})
export class AboutComponent implements OnInit {
constructor() {}
ngOnInit() {}
}