我正在尝试构建一个简单的无限滚动。它加载数据很好,但加载后,新添加的元素指令不起作用。
这是滚动检查和数据加载指令的相关部分。
.directive("scrollCheck", function ($window, $http) {
return function(scope, element, attrs) {
angular.element($window).bind("scroll", function() {
// calculating windowBottom and docHeight here then
if (windowBottom >= (docHeight - 100)) {
// doing some work here then
$http.get('service page').then(function (result) {
if (result.data.trim() != "") {
var newDiv = angular.element(result.data);
element.append(newDiv);
}
// doing some other work
},function () {
// error handling here
});
}
scope.$apply();
});
};
})
服务页面将此结构的一些重复返回为result.data
<div ...>
<div ... ng-click="test($event)"></div>
<div ...>...</div>
</div>
正如我所说,数据加载得很好,但test()
指令中的ng-click
函数不起作用。如何让他们工作?
答案 0 :(得分:2)
我相信你需要编译返回的html元素。像这样的东西
public class User {
String user_id;
String user_token;
String first_name;
String last_name;
//Getter and Setters
}
您需要确定并将$ compile传入您的函数