我想在http请求发送数据到控制器之后和数据绑定到控制器之后调用javascript函数。有没有这样的角度方法?
答案 0 :(得分:0)
$ timeout是你最好的选择。但是,这需要您使用Angular生命周期。没有事件要知道HTTP请求正在等待或完成,您需要跟踪您感兴趣的请求的状态。
如果你试图从Angular生命周期之外调用一个普通的JavaScript函数,我会质疑你想要做什么。
答案 1 :(得分:0)
您可以使用标志来实现它。
关于http请求成功将此变量设置为true。现在将进行dom渲染..要知道ng-repeat是否已完成,请创建一个指令,如
<div ng-controller="Ctrl">
<div ng-repeat="test in testing" repeat-completed>
{{test}}
</div>
</div>
angular.module('myApp', [])
.directive('repeat-completed', function() {
return function(scope, element, attrs) {
if (scope.$last){
//do whatever you want to do
}
};
});
答案 2 :(得分:0)
您可以使用“$ watch”服务来实现此目的。
$ watch service持续观看模特。只要模型的值发生变化,它就会运行监听功能
Syntax: scope.$watch('watchExpression ( this can be your model )' , function() {
// this is a listener function you can define here
// actions to perform
})
请按照下面的链接进行操作。 https://docs.angularjs.org/api/ng/type/ $ rootScope.Scope#$表