Skip to content
This repository was archived by the owner on Feb 2, 2025. It is now read-only.

Fix getList and getLast #242

Closed
wants to merge 2 commits into from
Closed

Fix getList and getLast #242

wants to merge 2 commits into from

Conversation

miguelqvd
Copy link
Contributor

This fixes the issue when trying to access getList and getLast and the tables haven't been still registered.

This can be tested here: http://plnkr.co/edit/I1BEU6lIdFkAqxxwGadf

@miguelqvd
Copy link
Contributor Author

I've corrected minor merge issues.

@l-lin
Copy link
Owner

l-lin commented Mar 11, 2015

Unfortunately, if you remove the variable assignment in the $scope, the console displays undefined. See plnkr. 😢

@miguelqvd
Copy link
Contributor Author

Sorry, I don't understand your point, the promise returns the instances as expected and the reason because the $scope.instancesFound is undefined is because it has never been assigned.

var app = angular.module('plunker', ['datatables']);

app.controller('MainCtrl', function($scope, DTInstances) {
  $scope.name = 'World';

  DTInstances.getList().then(function(dtInstances){
    console.log($scope.instancesFound);
  });

  $scope.onCheckDTInstancesClick = function(){
      DTInstances.getList().then(function(dtInstances){
        console.log($scope.instancesFetched);
      });
  };
});

I think it should be:

var app = angular.module('plunker', ['datatables']);

app.controller('MainCtrl', function($scope, DTInstances) {
  $scope.name = 'World';

  DTInstances.getList().then(function(dtInstances){
    console.log(dtInstances);
    $scope.instancesFound = dtInstances;
  });

  $scope.onCheckDTInstancesClick = function(){
      DTInstances.getList().then(function(dtInstances){
        console.log(dtInstances);
        $scope.instancesFetched = dtInstances;
      });
  };
});

I've updated my plunkr http://plnkr.co/edit/I1BEU6lIdFkAqxxwGadf

l-lin added a commit that referenced this pull request Mar 11, 2015
@l-lin
Copy link
Owner

l-lin commented Mar 11, 2015

My bad 😅 I read your plnkr too quickly and I thought I read console.log(dtInstances); instead of console.log($scope.instancesFound). So I thought it could only work if the dtInstances is assigned to an Angular $scope or linked to the Angular digest (which is not true).

However, your code in the pull request does not work, but the code in your plnkr does.
So I used the latter.

Thanks for your contribution. You're awesome! 👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants