После поиска в Stackoverflow предыдущего поста большинство решений не решают мою проблему.
Мигрирую из jquery в angularjs. Мне нужно преобразовать эти три строки кодов из jquery в angularjs
$(window).scroll(function(){
var position = $(window).scrollTop();
var bottom = $(document).height() - $(window).height();
Вот рабочий код для jquery , который оповещает о положении и нижних значениях
<script>
$(document).ready(function(){
$(window).scroll(function(){
var position = $(window).scrollTop();
var bottom = $(document).height() - $(window).height();
alert(position);
alert(bottom);
if( position == bottom ){
/*
$.ajax({
url: 'fetch_data.php',
type: 'post',
data: {row:20},
success: function(response){
$(".post:last").after(response).show().fadeIn("slow");
}
});
*/
}
});
});
</script>
Вот моя борьба с angularjs , но я не могу заставить его работать. Может ли кто-нибудь помочь мне
<script>
var fetch = angular.module('myapp', []);
fetch.controller('fetchCtrl', ['$scope', '$http','$window', function ($scope, $http, $window) {
angular.element($window).bind("scroll", function() {
var position = $(window).scrollTop();
var bottom = $(document).height() - $(window).height();
alert(position);
alert(bottom);
if( position == bottom ){
/*
$scope.getPosts = function(){
$http({
method: 'post',
url: 'getData.php',
data: {row:20}
}).then(function successCallback(response) {
$scope.posts = response.data;
});
}
*/
}
});
}]);
</script>