首页 技术 正文
技术 2022年11月11日
0 收藏 938 点赞 3,328 浏览 3003 个字

A factory which creates a resource object that lets you interact with RESTful server-side data sources.

The returned resource object has action methods which provide high-level behaviors without the need to interact with the low level $http service.

Requires the ngResource module to be installed.

A resource “class” object with methods for the default set of resource actions optionally extended with custom actions. The default set contains these actions:

{
'get': {method:'GET'},
'save': {method:'POST'},
'query': {method:'GET', isArray:true},
'remove': {method:'DELETE'},
'delete': {method:'DELETE'}
}

Let’s try to use that

_Layout.cshtml

<!DOCTYPE html>
<html ng-app="app">
<head>
<title></title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<base href="/" rel="external nofollow" >
</head>
<body>
<!--<ul>
<li>
<a href="#/users" rel="external nofollow" >Users</a>
</li>
<li>
<a href="#/roles" rel="external nofollow" >Roles</a>
</li>
</ul>--> <ul>
<li>
<a ui-sref="users">Users</a>
</li>
<li>
<a ui-sref="roles">Roles</a>
</li>
</ul> <ul>
<li>
<a href="/users" rel="external nofollow" >Users</a>
</li>
<li>
<a href="/roles" rel="external nofollow" >Roles</a>
</li>
</ul> @RenderBody() <script type="text/javascript" src="/Scripts/libs/angular/angular.min.js"></script>
<!--<script type="text/javascript" src="/Scripts/libs/angular/angular-route.min.js"></script>-->
<script type="text/javascript" src="/Scripts/libs/angular/angular-resource.min.js"></script>
<script type="text/javascript" src="/Scripts/libs/angular-ui/ui-router/angular-ui-router.min.js"></script>
<script type="text/javascript" src="/Scripts/app/app.js"></script>
<script type="text/javascript" src="/Scripts/app/components/users/app.users.js"></script>
<script type="text/javascript" src="/Scripts/app/components/users/app.users.routes.js"></script>
<script type="text/javascript" src="/Scripts/app/components/users/services/user.service.js"></script>
<script type="text/javascript" src="/Scripts/app/components/users/controllers/user.controller.js"></script>
<script type="text/javascript" src="/Scripts/app/components/roles/app.roles.js"></script>
<script type="text/javascript" src="/Scripts/app/components/roles/app.roles.routes.js"></script>
<script type="text/javascript" src="/Scripts/app/components/roles/controllers/role.controller.js"></script>
</body>
</html>

app.users.js

(function() {
'use strict'; angular
.module('app.users', [
//'ngRoute',
'ngResource',
"ui.router"
]);})();

user.service.js

(function() {
'use strict'; angular
.module('app.users')
.factory('UserService', ['$resource', function($resource) {
return $resource(('/api/users/:id'), { id: '@Id' }, {
list: { method: 'POST', url: '/api/users/list', isArray: true },
get: { method: 'GET' },
getNew: { method: 'GET', url: '/api/users/getnew' },
create: { method: 'POST' },
update: { method: 'PUT' },
delete: { method: 'DELETE' }
});
}]);})();

user.controller.js

(function() {
'use strict'; angular
.module('app.users')
.controller('UserController', ['$scope', 'UserService', function($scope, userService) {
$scope.users = userService.list();
}]);})();

user-list.tpl.html

<h2>Users</h2><table>
<thead>
<tr>
<th>
First name
</th>
<th>
Last name
</th>
<th>
Email
</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="user in users">
<td>
{{user.FirstName}}
</td>
<td>
{{user.LastName}}
</td>
<td>
{{user.Email}}
</td>
</tr>
</tbody>
</table>
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,156
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,624
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,468
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,240
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,876
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,043