Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery angular4中的事件绑定_Jquery_Angular_Typescript - Fatal编程技术网

Jquery angular4中的事件绑定

Jquery angular4中的事件绑定,jquery,angular,typescript,Jquery,Angular,Typescript,我想使用angular4调用单击事件绑定ngonit()上的单击事件的方法。我的要求是在我已经完成的span上绑定click事件,但当我使用if条件调用其他方法时,会出现错误this.getSellingChats不是console中的函数。这是我的密码 ngOnInit() { this.scrollToBottom(); this.getallChats(); this.checkConnection(); setTimeout(() => { this.bindClick

我想使用angular4调用单击事件绑定ngonit()上的单击事件的方法。我的要求是在我已经完成的span上绑定click事件,但当我使用if条件调用其他方法时,会出现错误this.getSellingChats不是console中的函数。这是我的密码

ngOnInit() { 

this.scrollToBottom();
this.getallChats();
this.checkConnection();
setTimeout(() => {
    this.bindClickevents();    
}, 3000);

}

bindClickevents(){
$('tabset ul li a').find('span').bind('click',function(event){

    var _tab = $(this).text();
    if(_tab == 'ALL'){
        this.getallChats();
    }
    else if(_tab == 'SELLING'){
        this.getSellingChats();

    }
    else if(_tab == 'BUYING'){
        this.getBuyingChats();
    }
    else if(_tab == 'BLOCKED'){
        this.getBlockedChats();
    }
});
}

基本上,我想要实现的是绑定span上的click事件,然后用户单击不同的选项卡,根据if条件调用不同的方法。我不想在ngOnInit()方法中调用以下方法


请给我提供解决方案。非常感谢。

不是
查找方法中组件的参考。试试下面的方法

    bindClickevents(){
    const comp = this;
    $('tabset ul li a').find('span').bind('click',function(event){

        var _tab = $(this).text();
        if(_tab == 'ALL'){
            comp.getallChats();
        }
        else if(_tab == 'SELLING'){
            comp.getSellingChats();

        }
        else if(_tab == 'BUYING'){
            this.getBuyingChats();
        }
        else if(_tab == 'BLOCKED'){
            comp.getBlockedChats();
        }
    });
    }

解决方法是阅读。如果您使用JQuery来处理用户事件,那么使用Angular没有任何意义。是的,我已经在ts文件中声明了它。如何使用angular4实现事件绑定。如果你说使用角度传感器没有意义,请帮助我@trichetricheI不会给你一个关于堆栈溢出的角度路线。我为您提供了一个关于如何在Angular中处理用户点击的直接链接。现在您必须阅读它。我不能绑定(单击)事件,因为我的Html正在动态加载,这就是为什么我在这里使用jquery绑定单击事件。
    bindClickevents(){
    const comp = this;
    $('tabset ul li a').find('span').bind('click',function(event){

        var _tab = $(this).text();
        if(_tab == 'ALL'){
            comp.getallChats();
        }
        else if(_tab == 'SELLING'){
            comp.getSellingChats();

        }
        else if(_tab == 'BUYING'){
            this.getBuyingChats();
        }
        else if(_tab == 'BLOCKED'){
            comp.getBlockedChats();
        }
    });
    }