显示控件时调用函数



我有输入控制:

<input id="someID" class="form-control" type="text" name="SomeData"
data-ng-model="vm.SomeData">

我需要初始化值vm.SomeData当用户向下滚动到此控件时。我是棱角刚开始的,所以不确定是否有像"控件显示"这样的事件?

//html 
<input id="someID" when-scrolled="vm" class="form-control" type="text" name="SomeData" data-ng-model="vm.SomeData">
//try this directive
app.directive("whenScrolled", function(){
return {  
restrict: 'A',
link: function(scope, elem, attrs){
// we get a list of elements of size 1 and need the first element
raw = elem[0];    
// we load more elements when scrolled past a limit
elem.bind("scroll", function(){
if(raw.scrollTop+raw.offsetHeight+5 >= raw.scrollHeight){
scope.vm.name = 'Nainish Modi';
// we can give any function which loads more elements into the list
scope.$apply(attrs.whenScrolled);
}
});
}
}
});

最新更新