简单restangular例如打破了AngularJS 1.2 [英] Simple restangular example broken with AngularJS 1.2
问题描述
我在做一个基本的 Restangular
的例子,它适用于 AngularJS 1.1
,但在 1.2
的 REST
请求被发送,接收数据,但无法正确显示表。
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.
我通过一些线程在这里阅读有关从 1.1〜1.2
升级,但我没有看到这个问题的例子非常简单,没有明确使用 ngRoute
,孤立的作用域或自定义的指令。
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.2?
Any idea what is missing/incorrect in order to get this working properly on 1.2?
干杯,
推荐答案
我从来没有使用过 restangular
。看起来它返回一个承诺的1.2版本,而不是数据,我能与此稍作修改加载数据:
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;
});
});
这篇关于简单restangular例如打破了AngularJS 1.2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!