在完成加载angular js Scope元素、Directives和Http请求后是否发生任何事件
Is there any event after completly loading of angular js Scope elements and Directives and Http requests
我想在http请求将数据发送到控制器后以及在数据绑定到控制器后调用一个javascript函数。有这样的角度法吗?
$timeout将是您知道控制器和绑定已完成的最佳选择。然而,这需要您处于Angular生命周期中。没有事件可以知道HTTP请求是挂起的或完成的,您需要跟踪感兴趣的请求的状态。
如果你试图从Angular生命周期之外调用一个普通的JavaScript函数,我会质疑你想做什么
您可以通过使用标志来实现它。
- 在控制器上放置ng if="somevariableflag"
http请求成功后,将此变量设置为true。现在将进行dom渲染。。要知道ng重复是否完成,请创建类似的指令
<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
}
};
});
您可以通过使用"$watch"服务来实现这一点。
$watch服务持续观察模型。每当模型的值发生变化时,它就会运行侦听器函数
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#$watch
相关文章:
- Meteor如何接收HTTP请求
- 在我的情况下,如何进行http请求
- 使用插件收听Firefox标签的http请求
- Angularjs http.get() Cross-Origin 请求被阻止
- http请求使用html而不是json进行响应
- 在node-js路由中发出http请求
- 通过sdk/system/events在修改请求观测器上测试http
- 是否可以在没有HTTP请求或<输入>
- Acync JS HTTP请求通知请求
- PhantomJs在控制台中发出http请求时不会返回任何状态
- 当我在chrome中切换设备模式时,$http.get请求失败
- PHP处理来自一个页面的http请求,并将其显示在另一个页面上
- 使用angular js通过代理服务器请求Http
- 如何从HTTPS服务器请求HTTP服务器的javascript文件
- 阻止的跨来源请求:http://api.fixer.io/latest.
- 坏的请求.HTTP POST到api
- 有没有办法为AngularJS JSON请求($http/$resource)使用浏览器缓存?
- angular js在每个http请求$http上添加请求参数
- 当从不存在的站点请求HTTP响应时,Node.js脚本会中断
- 通过代理服务器请求HTTP呼叫