Ich benutze angularjs 1.5.8, die ich craete Komponentenname als Gruppe mit Gruppenmodul, ich erstelle Direktive des gleichen Moduls als Komponente namens blättern, Ich bin in erfordern Um die Komponentenfunktion aufzurufen, die loadmoregroups ist, um api dort aufzurufen, um beim Scrollen mehr Gruppen am Bootom zu erhalten.Wie winkeln Komponente Funktion von außen Direktiven
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
}
});
}
};
});
Die beste Vorgehensweise ist mit rootScope mit Funktionen zu vermeiden. Sehen Sie mehr hier: http://Stackoverflow.com/questions/32761540/why-using-rootscope-with-functions-is-not-recommended –