Im试图对我的div使用scrolly指令。当用户向下滚动并结束div时,我想调用一个函数。它给我未定义的范围。$ apply函数? 请任何一个帮助。 Thankx提前 这里是我的html代码
<div id="container" style="
position:absolute;
top: 60px;
width: 100%;
left:0px;height:91%;overflow-y:scroll;" scrolly="showMore()" >
这里是应用程序和控制器
var app = angular.module('smac',[]);
app.controller('asd',function ($http,$scope) {
$scope.showMore = function(){
alert('div finished');
}
});
和指令是
app.directive('scrolly', function() {
return {
restrict: 'A',
link: function (scope, element, attrs) {
var raw = element[0];
console.log('loading directive');
element.bind('scroll', function() {
console.log('in scroll');
console.log(raw.scrollTop + raw.offsetHeight >= raw.scrollHeight)
if (raw.scrollTop + raw.offsetHeight >= raw.scrollHeight) {
scope.$apply(attrs.scrolly)
console.log(scope.$apply(attrs.scrolly)); // this is undefined
}
});
}
};
});
该控制台日志正在打印作用域的返回值$ apply,我敢打赌是未定义的。如果你想检查的范围,$ apply本身是未定义的,你需要使用。 'console.log(scope。$ apply);' –
为什么它返回undefined? @ZacBraddy – Asad
你真正的问题是什么?你想要达到什么目标,而且哪些不起作用? – kabaehr