I have a simple text which is a hyperlink and upon clicking, it just opens up a div with fadeIn property. I have done this with the use of jQuery in my angular-cli project. But I have come to understand that jQuery combination with angular is not advisable.
dashboard.html
<div class="groupMembersPopup" #myname>
........ group is selected from list in this div and binding it to selectGroupName var
</div>
<div class="selectPostTo cf">
<label>Post to</label>
<a class="selectPostType" (click)="loadPostGroups($event)">{{selectGroupName}}</a>
</div>
<div class="overlayPopup1"></div>
dashboard.ts
@ViewChild('myname') input;
constructor( private _elementRef: ElementRef){}
ngOnInit() {
let el = this._elementRef.nativeElement;
let t =
this._elementRef.nativeElement.querySelector('groupMembersPopup');
console.log(t);
}
loadPostGroups(event) {
this.startGroup = 0;
this.endGroup = 100;
this.group_list = [];
this.getUserGroups(this.startGroup, this.endGroup);
}
main.js
if ($(".groupMembersPopup").length) {
$('.selectPostType').click(function () {
$('.groupMembersPopup').addClass('show');
$('.overlayPopup1').fadeIn();
return false;
});
$('.overlayPopup1, .groupMembersPopup .btnRemove').click(function () {
$('.groupMembersPopup').removeClass('show');
$('.overlayPopup1').fadeOut();
return false;
});
}
I have included my main.js files in scripts inside angular-cli.json file. Uptil now I was using jquery in this manner. How can I transform my jQuery code inside the typescript. I have SO it and found that Elementref can be used. Tried it but couldn't be able to figure it out.
ElementRef?