ionic1 页面html渲染完成之后函数封装
html
<ul>
<li ng-repeat="item in items" on-finish-render="callMethod()">
dummy Text
</li>
</ul>
app.js定义服务指令
//angularjs渲染完执行
.directive('onFinishRender',['$timeout', '$parse', function ($timeout, $parse) {
return {
restrict: 'A',
link: function (scope, element, attr) {
if (scope.$last === true) {
$timeout(function () {
scope.$emit('ngRepeatFinished'); //事件通知
var fun = scope.$eval(attr.onFinishRender);
if(fun && typeof(fun)=='function'){
fun(); //回调函数
}
});
}
}
}
}])
用法
//ng-repeat执行完在执行
$scope.$on('ngRepeatFinished', function(ngRepeatFinishedEvent) {
$scope.callMethod = function(){
console.log("渲染完成了")
}
})