AngularJS Best Practices: resource
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了AngularJS Best Practices: resource,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3907字,纯文字阅读大概需要6分钟。
内容图文
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
' ref='nofollow'> 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="/"></head><body><!--<ul> <li> <a href="#/users">Users</a> </li> <li> <a href="#/roles">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">Users</a></li><li><a href="/roles">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>
原文:http://www.cnblogs.com/zhangpengc/p/5052885.html
内容总结
以上是互联网集市为您收集整理的AngularJS Best Practices: resource全部内容,希望文章能够帮你解决AngularJS Best Practices: resource所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。