{"id":1075,"date":"2015-07-31T13:22:58","date_gmt":"2015-07-31T13:22:58","guid":{"rendered":"http:\/\/www.honobono-life.info\/wpeng\/?p=1075"},"modified":"2015-07-31T13:22:58","modified_gmt":"2015-07-31T13:22:58","slug":"angularjs-resource-rest-service","status":"publish","type":"post","link":"http:\/\/www.honobono-life.info\/wpeng\/angularjs-resource-rest-service\/","title":{"rendered":"Ruby on Rails Tutorial AngularJS $resource, REST service"},"content":{"rendered":"<p><strong>1)AngularJS $resource REST factory<\/strong><\/p>\r\n\r\n<p>$ vi app\/assets\/javascripts\/mymodule.js.erb<\/p>\r\n\r\n<pre class=\"prettyprint\">\r\nmyModule = angular.module(&#39;myModule&#39;, [&#39;ui.bootstrap&#39;,&#39;ngRoute&#39;,&#39;ngResource&#39;]);\r\n\r\nmyModule.factory(&quot;userResource&quot;, function($resource) {\r\n  return $resource(&quot;\/app\/users\/:id&quot;, { id: &quot;@id&quot; },\r\n    {\r\n      &#39;create&#39;:  { method: &#39;POST&#39; },\r\n      &#39;index&#39;:   { method: &#39;GET&#39;, isArray: true },\r\n      &#39;show&#39;:    { method: &#39;GET&#39;, isArray: false },\r\n      &#39;update&#39;:  { method: &#39;PUT&#39; },\r\n      &#39;destroy&#39;: { method: &#39;DELETE&#39; }\r\n    }\r\n  );\r\n});<\/pre>\r\n\r\n<p><strong>2)AngularJS index controller<\/strong><\/p>\r\n\r\n<p>$ vi app\/assets\/javascripts\/mymodule.js.erb<\/p>\r\n\r\n<pre class=\"prettyprint\">\r\nmyModule.controller(&quot;UsersIndexCtrl&quot;, function($scope,userResource) {\r\n  $scope.users = userResource.index()\r\n});<\/pre>\r\n\r\n<p>&nbsp;<\/p>","protected":false},"excerpt":{"rendered":"<p>1)AngularJS $resource REST factory $ vi app\/assets\/javascripts\/mymodule.js.erb myModule = angular.module(&#39;myModule&#39;, [&#39;ui.bootstrap&#39;,&#39;ngRoute&#39;,&#39;ngResource&#39;]); myModule.factory(&quot;userResource&quot;, function($resource) { return $resource(&quot;\/app\/users\/:id&quot;, { id: &quot;@id&quot; }, { &#39;create&#39;: { method: &#39;POST&#39; }, &#39;index&#39;: { method: &#39;GET&#39;, isArray: true }, &#39;show&#39;: { method: &#39;GET&#39;, isArray: false }, &#39;update&#39;: { method: &#39;PUT&#39; }, &#39;destroy&#39;: { method: &#39;DELETE&#39; } } ); }); 2)AngularJS index [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[137],"tags":[146,35,147],"amp_enabled":true,"_links":{"self":[{"href":"http:\/\/www.honobono-life.info\/wpeng\/wp-json\/wp\/v2\/posts\/1075"}],"collection":[{"href":"http:\/\/www.honobono-life.info\/wpeng\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.honobono-life.info\/wpeng\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.honobono-life.info\/wpeng\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.honobono-life.info\/wpeng\/wp-json\/wp\/v2\/comments?post=1075"}],"version-history":[{"count":1,"href":"http:\/\/www.honobono-life.info\/wpeng\/wp-json\/wp\/v2\/posts\/1075\/revisions"}],"predecessor-version":[{"id":1076,"href":"http:\/\/www.honobono-life.info\/wpeng\/wp-json\/wp\/v2\/posts\/1075\/revisions\/1076"}],"wp:attachment":[{"href":"http:\/\/www.honobono-life.info\/wpeng\/wp-json\/wp\/v2\/media?parent=1075"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.honobono-life.info\/wpeng\/wp-json\/wp\/v2\/categories?post=1075"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.honobono-life.info\/wpeng\/wp-json\/wp\/v2\/tags?post=1075"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}