Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/445.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
Javascript 在jQuery函数中调用函数_Javascript_Function_Angular - Fatal编程技术网

Javascript 在jQuery函数中调用函数

Javascript 在jQuery函数中调用函数,javascript,function,angular,Javascript,Function,Angular,我想在JQuery方法中执行一个exeenal函数。当我尝试调用该方法时出现问题,该方法看起来未定义。我怎样才能解决这个问题?我使用带有角度2的Typescript进行amb ngAfterViewInit() { jQuery(".mo-table").scroll(function () { var trueDiveHeight = jQuery(".mo-table")[0].scrollHeight; var divHeight = jQuery(".mo-table").he

我想在JQuery方法中执行一个exeenal函数。当我尝试调用该方法时出现问题,该方法看起来未定义。我怎样才能解决这个问题?我使用带有角度2的Typescript进行amb

ngAfterViewInit() {

jQuery(".mo-table").scroll(function () {
  var trueDiveHeight = jQuery(".mo-table")[0].scrollHeight;
  var divHeight = jQuery(".mo-table").height();
  var scrollLeft = trueDiveHeight - divHeight;

  if (jQuery(".mo-table").scrollTop() >= scrollLeft - 150) {

    this.onSearch();

    console.log("new bottom")
   }
 });
}
onSearch方法是一个外部函数,未定义

onSearch(): void {      
  this.updateTableReport(this.scrollId, this.buildParams())
}
任何帮助都将不胜感激

变化

jQuery(".mo-table").scroll(function () {

您的
不是指您的组件

还是老办法:

ngAfterViewInit() {

var self = this; //<-- assign this to self here
jQuery(".mo-table").scroll(function () {
  var trueDiveHeight = jQuery(".mo-table")[0].scrollHeight;
  var divHeight = jQuery(".mo-table").height();
  var scrollLeft = trueDiveHeight - divHeight;

  if (jQuery(".mo-table").scrollTop() >= scrollLeft - 150) {

    self.onSearch(); //<-- use self here

    console.log("new bottom")
   }
 });
}
ngAfterViewInit(){
var self=this;//=scrollLeft-150){

self.onSearch();//可能是重复的!谢谢,我不知道“self”逻辑。这是为什么?我的意思是,当我们分配给它时,是否获得整个页面的引用?@XGuy当你在javascript中使用work
函数时,你正在创建一个新的作用域。这个作用域中的
this
引用了这个函数的let say实例。因此
this
将引用和中的不同内容退出此功能。有关的详细信息:
ngAfterViewInit() {

var self = this; //<-- assign this to self here
jQuery(".mo-table").scroll(function () {
  var trueDiveHeight = jQuery(".mo-table")[0].scrollHeight;
  var divHeight = jQuery(".mo-table").height();
  var scrollLeft = trueDiveHeight - divHeight;

  if (jQuery(".mo-table").scrollTop() >= scrollLeft - 150) {

    self.onSearch(); //<-- use self here

    console.log("new bottom")
   }
 });
}