我为MEAN堆栈应用程序中的下拉列表编写了一个自定义指令,但无法将滚动函数绑定到它。这是指令代码:
.directive('inputDropdown', function($parse) {
var template =
'<input class="form-control" ng-model="ngModel" ng-disabled="disabled" placeholder="Type Name">' +
'<div class="dropdown dropdown1">' +
'<div class="form-control" ng-repeat="value in selectedList | filter:ngModel | limitTo:limit">' +
'<div ng-mousedown="select($event, value)">{{value}}</div>' +
'</div>' +
'</div>';
return {
restrict: 'EA',
require: '^form',
scope: {
ngModel: '=',
list: '=',
onSelect: '&',
disabled:'=ngDisabled'
},
template: template,
link: function(scope, element, attrs,mapController) {
element.addClass('input-dropdown');
angular.element(document.querySelector('input-dropdown')).bind('scroll', function(){ //1st way
alert('scrolling is cool!');
});
// element.scroll(function (evt) { //2nd way
// alert('scrolling is nama-cool!');
// });
if(scope.$parent.setDirty)
{
scope.makeFormDirty = mapController.$setDirty();
}
scope.select = function(e, value) {
scope.ngModel = value;
// scope.onSelect({$event: e, value: value});
scope.makeFormDirty = mapController.$setDirty();
};
}
};
})
我尝试绑定滚动功能的方法有两种,但没有一种方法可以正常工作。
第一种方式:
angular.element(document.querySelector('input-dropdown')).bind('scroll', function(){ //1st way
alert('scrolling is cool!');
});
第二种方式:
element.scroll(function (evt) { //2nd way
alert('scrolling is nama-cool!');
});
答案 0 :(得分:0)
您似乎缺少'.input-dropdown'
并使用.on('scroll')
.bind
已弃用,您应该使用.on
。请参阅document
应该是
angular.element(document.querySelector('.input-dropdown')).on('scroll', function(){ //1st way
alert('scrolling is cool!');
});