0

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.

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 ...!!!

but it's not working , ng-model ='xxxx' is giving undefined always.

Thanks in Advance.

2
  • The Question is how to check Weather data in the Table is loaded or not ? Commented Jul 24, 2014 at 14:28
  • Please consider adding a comment when voting down so that the question can be improved. Thanks. Commented Aug 13, 2014 at 12:16

3 Answers 3

1

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;
});
Sign up to request clarification or add additional context in comments.

2 Comments

@PraveenPrakashDSouza sorry, don't understand what you ask. In my case, data parameter will already contain information when executing controller, controller loads after promise is resolved
The Question is how to check Wether data in the Table is loaded or not ? but how this approch will make sure that domElement has been completly loaded...???
0

You have put ngModel on a table tag which is incorrect. ngModel works only on a user input element:

  • input
  • text
  • checkbox
  • radio
  • number
  • email
  • url
  • date
  • dateTimeLocal
  • time
  • month
  • week
  • select
  • textarea

See docs: https://docs.angularjs.org/api/ng/directive/ngModel

2 Comments

I agree on your point , But i was expecting of solution for above question ,,
Your syntax is incorrect. ngModel doesn't work for table. Try ngModel on some input, that is the solution.
0

I think you have a misunderstanding of when ng-model is used. ng-model is used to bind form controls to data in the $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. 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.

For example, you can use 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.

1 Comment

i Agree on your point.When nothing works , i m trying these kind of tricks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.