显示控制时的调用功能

时间:2017-07-06 09:51:27

标签: html angularjs

我有输入控件:

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

当用户向下滚动到此控件时,我需要初始化值vm.SomeData。我是棱角分明的新人,所以不确定是否会出现像ControlDisplayed&#39;

这样的事件?

1 个答案:

答案 0 :(得分:0)

 //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);
         }
       });
      }
    }
 });