【发布时间】:2017-03-21 15:07:02
【问题描述】:
我正在使用 angularjs 1.5.8,我使用 group 模块将组件名称创建为 Group,同样我创建了与名为 scroll 的组件相同的模块的指令, 我需要调用组件函数 loadmoregroups 来调用 api 以在启动时滚动获取更多组。
angular.module('group', []).
component('group', {
templateUrl: '/djangotemplates/private/group/list.html',
controller: function(
$cookies,
$http,
$location,
$scope,
Flash,
$animate,
Group,
$timeout,
$rootScope
){
$rootScope.loadMoreGroups =function()
{
alert("loadmore");
}
}
}).directive('scroll', function() {
return {
restrict: 'A',
link: function(rootScope, element, attrs, $window, $scope, $document) {
var bind = element.bind('tbody');
var raw = element[0];
angular.element(bind).on("scroll", function() {
//console.log('in scroll mode');
if (raw.scrollTop + raw.offsetHeight >= raw.scrollHeight) {
**rootScope.loadMoreGroups();** //unable to call this `enter code here`function
}
});
}
};
});
【问题讨论】:
-
最佳实践是避免将 rootScope 与函数一起使用。在此处查看更多信息:stackoverflow.com/questions/32761540/…
标签: angularjs