How To Use Get Element By Id In Angular 7


appComponent.ts

import { Component, ElementRef, OnInit, ViewChild } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
  name = 'Angular';
  @ViewChild('self_user3') self_user3: string;
  ngOnInit(): void {
    const article = document.querySelector('#self_user');
    document.getElementById('self_user1').textContent = '<b>Mr. Pukar</b>';
    document.getElementById('self_user2').innerHTML = '<b>Mr. Pukar</b>';
    console.log(this.self_user3.nativeElement.value);
  }
 }

appComponent.html
<div id="self_user1" ></div><br>
<div id="self_user2" ></div><br>
<input type="text" #self_user3 value="Some One"><br>

Output


Share on Google Plus

About Ram Pukar

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment

0 comments:

Post a Comment