[英]How to check data is loaded in table or Not using Angular js
I need to check whether data is loaded or not in the Table ? 我需要检查表中是否已加载数据?
Based on this some decision , i need to perform some operation on it, 基于这个决定,我需要对其执行一些操作,
Only Angular js solution please. 请只有Angular js解决方案。
html HTML
<table ng-model='xxxx'>
<tr ng-repeat="x in obj" ng-bind='x.name'>---</tr>
<table>
Angular snippet: 角度片段:
$scope.$watch('xxxx', function (val) {
console.log(val);
if (val !== undefined) {
collectData();
}
});
i was trying to place one ng-model and finding its value in $watch and find the table is ready for operation or not ...!!! 我试图放置一个ng模型并在$ watch中找到其值,并发现该表已准备好进行操作...!
but it's not working , ng-model ='xxxx' is giving undefined always. 但它不起作用,ng-model ='xxxx'总是给出undefined。
Thanks in Advance. 提前致谢。
You can execute controller after data loads like this: 您可以在数据加载后执行控制器,如下所示:
$routeProvider.when({
url: '/',
controller: 'myCtrl',
templateUrl: 'myTemplate.html',
resolve: {
data: function(mySrvc){
return mySrvc.getData().$promise;
}
}
});
app.controller('myCtrl', function($scope, data){
// data is already loaded
$scope.data = data;
});
You have put ngModel
on a table tag which is incorrect. 您已将
ngModel
放在错误的表标签上。 ngModel
works only on a user input element: ngModel
仅适用于用户输入元素:
See docs: https://docs.angularjs.org/api/ng/directive/ngModel 参见文档: https : //docs.angularjs.org/api/ng/directive/ngModel
I think you have a misunderstanding of when ng-model is used. 我认为您对何时使用ng-model有误解。 ng-model is used to bind form controls to data in the $scope.
ng-model用于将表单控件绑定到$ scope中的数据。 For example, you can bind a input, text, checkbox, radio, number, email, url, date, dateTimeLocal, time, month, week, select, or textarea control to the $scope.
例如,您可以将输入,文本,复选框,单选,数字,电子邮件,URL,日期,dateTimeLocal,时间,月,周,选择或文本区域控件绑定到$ scope。 It doesn't have anything to do with tables.
它与表没有任何关系。
You could make an all new directive which would bind to a table, but there is no point in doing that because there are already means in AngularJS to render tables and other read-only data structures in the DOM. 您可以创建一个可以绑定到表的全新指令,但是这样做毫无意义,因为AngularJS中已经存在在DOM中渲染表和其他只读数据结构的方法。
For example, you can use ng-repeat: 例如,您可以使用ng-repeat:
<table>
<tr ng-repeat="state in states">
<td>{{ state.name }}</td>
<td>{{ state.population }}</td>
</tr>
</table>
But ng-model is usually used in those cases where there is a control and the user will be entering in data which will then automatically update the $scope variable bound to the control. 但是ng-model通常用于存在控件的情况下,用户将输入数据,然后这些数据将自动更新绑定到控件的$ scope变量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.