There is a lot of components and directives out there that can aide when nessecary. However I would like to obtain some basic understanding of how one would go from some standard js og jquery and implementing it into an Angular component.
I have found this html, css and javascript code that I would like to transform into an Angular Component: https://foundation.zurb.com/building-blocks/blocks/table-expand.html
Here is the JS
$('[data-open-details]').click(function (e) {
e.preventDefault();
$(this).next().toggleClass('is-active');
$(this).toggleClass('is-active');
});
How would i go about this? Taking this into a component.ts? And without the use of Jquery.
Thanks
Update
I need to reference my element with ViewChild and Elemenref. Here is where i am at.
export class TaskListComponent implements OnInit {
@ViewChild("detailopen") detailopen : ElementRef;
constructor(private rendere : Renderer2) { }
ngOnInit() {
let element = this.detailopen.nativeElement;
this.rendere.listen(element, 'click', (e)=>{
e.preventDefault();
//Do something that open or closes the accordion
})
}
}
And i have a template reference element on my html element called #detailopen
Update
So i moved away from above and simply created a click event that set isActive to true or false
export class TaskListComponent implements OnInit {
// @ViewChild("detailopen") detailopen : ElementRef;
constructor() { }
isActive;
ngOnInit() {
}
detailopen(event: MouseEvent){
event.preventDefault();
this.isActive = !this.isActive;
}
}
This will however open all content sections whenever i click one header. How can i prevent all content sections to open and just open the one that i want to target.