How to perform DOM manipulation in Angular components?
问题 How do we get hold of DOM elements in Angular (Version 2.x and above)? The basic functions like addClass, removeClass etc are not availble in typescript so how do we do these DOM manipulations in angular components? Please suggest if any. TIA 回答1: You can reach your DOM elements by using ViewChild decorator in this way: @Component({ .... templateUrl: 'mytemplate.html' }) export class MyComponent{ @ViewChild('selector') private someName; constructor() { //this is your dom //this.someName