1

I'm trying to create a application with angular 2,i have an <a> tag and using ("click") event.I want when an component rendering finished my a tag trigger click using jquery.But not working ! here is my .HTML code :

     <a href="" id="all_m" ('click')="test($event)"></a> 

in my another component : export class inside_group_page implements OnInit{

        ngOnInit(){
             jQuery("#all_m").trigger("click");
        }

1 Answer 1

2

do not use jquery with ng2

@Component({
   selector: 'inside-page-group',
   template: `<a #all_m href="" ('click')="test($event)"></a>`
}
export class InsideGroupPage {
   @ViewChild('all_m')
   private allMElementRef;

   constructor(@Inject(Renderer) private renderer: Renderer){
   }

   ngAfterViewInit() {
       this.renderer.invokeElementMethod(this.allMElementRef.nativeElement, 'click', []);
   }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.