1

I'm doing a basic Restangular example and it works on AngularJS 1.1, however on 1.2, the REST request is sent, data is received, but the table is not displayed properly.

I read through some threads here about upgrading from 1.1 to 1.2 but I don't see the issue as the example is very simple and does not explicitly use ngRoute, isolated scopes or custom directives.

HTML

<!DOCTYPE html>

<html ng-app="countries">

  <head>
    <meta charset="utf-8" />
    <title>REST Country Example</title>
    <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
    <script src="//code.angularjs.org/1.2.27/angular.min.js"></script>
    <script src="//code.angularjs.org/1.2.27/angular-resource.min.js"></script>
    <script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.7.0/underscore-min.js"></script>
    <script src="//cdn.rawgit.com/mgonto/restangular/master/dist/restangular.min.js"></script>

    <script src="app.js"></script>
  </head>

  <body ng-controller="mainCtrl">
    <div>
    <h2>Restangular Example with RESTCountries.eu</h2>


      <input type="text" ng-model="search" class="search-query" placeholder="Search">
      <table class="table table-responsive table-striped">
        <thead>
        <tr>
          <th>Country</th>
          <th>Capital</th>
          <th>Code</th>
        </tr>
        </thead>
        <tbody>
        <tr ng-repeat="country in countries | filter:search | orderBy:'name'">
          <td>{{country.name}}</td>
          <td>{{country.capital}}</td>
          <td>{{country.alpha2Code}}</td>
        </tr>
        </tbody>
      </table>

  </div>

  </body>

</html>

JS

app = angular.module('countries', ['restangular']);
app.config(function(RestangularProvider) {
      RestangularProvider.setBaseUrl('http://restcountries.eu/rest/v1');
  });

app.controller('mainCtrl', function($scope, Restangular) {
  $scope.countries = Restangular.all('all').getList();
});

1.1.5 Plunk (working)

1.2.27 Plunk (not working)

Any idea what is missing/incorrect in order to get this working properly on 1.2?

Cheers,

1 Answer 1

1

I have never used restangular before. Looks like it returns a promise for 1.2 version, instead of data, I am able to load the data with this minor modification:

app.controller('mainCtrl', function($scope, Restangular) {
  Restangular.all('all').getList().then(function(result) {
    $scope.countries = result;
  });
});

Plunker

Sign up to request clarification or add additional context in comments.

1 Comment

Aaaah... you're right, I overlooked removing promise unwrapping in 1.2. due to fa6e411d, promise unwrapping has been removed. It has been deprecated since 1.2.0-rc.3. It can no longer be turned on. Two methods have been removed: $parseProvider.unwrapPromises $parseProvider.logPromiseWarnings Thanks for the help.

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.