【发布时间】:2016-06-20 04:23:27
【问题描述】:
为什么我无法从事件处理程序中的this 关键字获取数据,如何解决?
twittyApp.factory('Unshown', function () {
function Unshown() {
this.allIsLoaded = false;
this.loading = false;
this.firstTime = true;
this.scrollMarker = 100;
this.loadedUnshownPages = 0;
this.timeLineHiader = $cookies.get("lastReadedTweetId");
}
window.onscroll = function () {
//why here this.scrollMarker is undefined?
};
return Unshown;
});
【问题讨论】:
-
把window.onscroll放到Unshown函数里面
-
如何在 onscroll 中访问 this.scrollMarker?
-
'var scrolled ....... if (this.scrollMarker > scrolled && !this.loading && !this.allIsLoaded) { this.loading = true;}'
标签: javascript angularjs web frontend