I am working on an angular app where I am displaying data of that variable this.result using one way data binding like {{this.result}}. When pressing submit, it will call one function which alter value of this.result. but it is not changing HTML view. It is showing old data. I guess this is happeing because I need to refresh HTML. For temporary fix I can do document.getElementById('').innerHTML = 'abcd', but I read some where you should not do innerHTML, getElementById in angular.
So, I have 2 question
- How to do instead of DOM Manipulation?
- Why not to do DOM manipulation? isn't it Angular internally uses DOM Manipulation?
I am doing a like button wh
Code snippet:
HTML File
<div style="text-align:right;border-top:1px solid black;border-bottom:1px solid black" [ngClass]="isLiked == true ? 'liked' : 'not-liked'">
{{ this.likedBy}} liked<i class="fa fa-thumbs-up" style="font-size:30px;" aria-hidden="true" (click)="toggle()"></i>
</div>
TypeScript file
toggle()
{
this.isLiked = !this.isLiked;
if(this.isLiked === true)
{
console.log('You liked this idea now');
this.likedBy.push(this.adalService.userInfo.profile.email);
}else{
console.log('You unliked this idea now');
this.likedBy.splice(this.likedBy.indexOf(this.adalService.userInfo.profile.email), 1);
}
console.log('Latest liker :- ' + this.likedBy)
}
In Console, I can see the field value is changing