在本地服务器上使用 restangular 创建一个 Demoapp
Creating a Demoapp using restangular at the local server
我对 angular js 很陌生,直到我使用 $resource 进行获取和放置,但现在我的要求是使用 Restangular
我在这里创建了一个演示程序
/* my json file with the name user.json */
{"user":[
{"id":1,
"subject":"#aashima"
},
{"id":2,
"subject":"#aansh"
},
{"id":3,
"subject":"#artle"
},
{"id":4,
"subject":"#harish"
}
]
}
<!doctype html >
<html ng-app="app">
<head>
<meta charset="UTF-8">
<title>Restangular</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.16/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/restangular/1.5.1/restangular.min.js"></script>
</head>
<body>
<div ng-controller="IndexCtrl as omega" ng-cloak>
<ul>
<li ng-repeat="result in omega.people">
<span ng-bind="result.subject"></span>
</li>
</ul>
</div>
<script>
var app = angular.module('app', ['restangular'])
.config(function(RestangularProvider) {
RestangularProvider.setBaseUrl("/js/user.json");
});
app.controller('IndexCtrl', function( Restangular) {
var self=this;
/*
self.people = Restangular.all('user').getList();
*/
Restangular.all('user').getList().then(function(result) {
self.people = result;
});
});
</script>
</body>
</html>
在此处输入图片描述
在控制台中它清楚地显示正在发出请求但没有数据
我无法删除导致此问题的错误,我们将不胜感激
var app = angular.module('app', ['restangular'])
.config(function(RestangularProvider) {
RestangularProvider.setBaseUrl("js");
});
app.controller('IndexCtrl', function( Restangular) {
var self=this;
/*
* We can use this one
self.people = Restangular.all('emp.json').getList().$object;
*/
/* or we can use this one */
Restangular.all('emp.json').getList().then(function(result) {
self.people = result;
});
});
/* this is should be the json response which is get */
[
{"id":1,
"subject":"#aashima"
},
{"id":2,
"subject":"#aansh"
},
{"id":3,
"subject":"#artle"
},
{"id":4,
"subject":"#harish"
}
]
所以这里将代表一个可以在本地服务器上实现的简单应用程序
我对 angular js 很陌生,直到我使用 $resource 进行获取和放置,但现在我的要求是使用 Restangular
我在这里创建了一个演示程序
/* my json file with the name user.json */
{"user":[
{"id":1,
"subject":"#aashima"
},
{"id":2,
"subject":"#aansh"
},
{"id":3,
"subject":"#artle"
},
{"id":4,
"subject":"#harish"
}
]
}
<!doctype html >
<html ng-app="app">
<head>
<meta charset="UTF-8">
<title>Restangular</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.16/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/restangular/1.5.1/restangular.min.js"></script>
</head>
<body>
<div ng-controller="IndexCtrl as omega" ng-cloak>
<ul>
<li ng-repeat="result in omega.people">
<span ng-bind="result.subject"></span>
</li>
</ul>
</div>
<script>
var app = angular.module('app', ['restangular'])
.config(function(RestangularProvider) {
RestangularProvider.setBaseUrl("/js/user.json");
});
app.controller('IndexCtrl', function( Restangular) {
var self=this;
/*
self.people = Restangular.all('user').getList();
*/
Restangular.all('user').getList().then(function(result) {
self.people = result;
});
});
</script>
</body>
</html>
在控制台中它清楚地显示正在发出请求但没有数据
我无法删除导致此问题的错误,我们将不胜感激
var app = angular.module('app', ['restangular'])
.config(function(RestangularProvider) {
RestangularProvider.setBaseUrl("js");
});
app.controller('IndexCtrl', function( Restangular) {
var self=this;
/*
* We can use this one
self.people = Restangular.all('emp.json').getList().$object;
*/
/* or we can use this one */
Restangular.all('emp.json').getList().then(function(result) {
self.people = result;
});
});
/* this is should be the json response which is get */
[
{"id":1,
"subject":"#aashima"
},
{"id":2,
"subject":"#aansh"
},
{"id":3,
"subject":"#artle"
},
{"id":4,
"subject":"#harish"
}
]
所以这里将代表一个可以在本地服务器上实现的简单应用程序