{"id":7523,"date":"2017-04-09T01:15:11","date_gmt":"2017-04-08T16:15:11","guid":{"rendered":"http:\/\/www.webcyou.com\/?p=7523"},"modified":"2017-04-09T01:15:11","modified_gmt":"2017-04-08T16:15:11","slug":"angular2%e3%81%ae%e5%a7%8b%e3%82%81%e6%96%b9%e3%80%82angular2-%e5%85%ac%e5%bc%8f%e3%83%81%e3%83%a5%e3%83%bc%e3%83%88%e3%83%aa%e3%82%a2%e3%83%ab-http%ef%bc%88%e7%b0%a1%e5%8d%98%e3%81%aa%e5%92%8c","status":"publish","type":"post","link":"https:\/\/www.webcyou.com\/?p=7523","title":{"rendered":"Angular2\u306e\u59cb\u3081\u65b9\u3002Angular2 \u516c\u5f0f\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb &#8211; HTTP\uff08\u7c21\u5358\u306a\u548c\u8a33\uff09"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/2016\/12\/angular_http.png\" alt=\"\" width=\"600\" height=\"300\" class=\"alignnone size-full wp-image-7755\" srcset=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/2016\/12\/angular_http.png 600w, https:\/\/www.webcyou.com\/wp-content\/uploads\/2016\/12\/angular_http-300x150.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/p>\n<h4>HTTP<\/h4>\n<p><strong>GETTING AND SAVING DATA<\/strong><\/p>\n<p>\u3053\u3061\u3089\u306e\u30da\u30fc\u30b8\u306f\u3001\u4ee5\u4e0b\u306e\u30da\u30fc\u30b8\u306e\u7c21\u5358\u306a\u548c\u8a33\u3067\u3059\u3002<\/p>\n<p><a href=\"https:\/\/angular.io\/docs\/ts\/latest\/tutorial\/toh-pt6.html\" target=\"_blank\">Angular2 tutorial | HTTP <\/a><\/p>\n<p><strong>\u524d\u56de<\/strong><br \/>\n<a href=\"https:\/\/www.webcyou.com\/?p=7521\">Angular2\u306e\u59cb\u3081\u65b9\u3002Angular2 \u516c\u5f0f\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb \u2013 Routing\uff08\u7c21\u5358\u306a\u548c\u8a33\uff09<\/a><\/p>\n<p><strong>\u305d\u306e\u4ed6<\/strong><\/p>\n<p><a href=\"https:\/\/www.webcyou.com\/?p=7519\">Angular2\u306e\u59cb\u3081\u65b9\u3002Angular2 \u516c\u5f0f\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb \u2013 Services\uff08\u7c21\u5358\u306a\u548c\u8a33\uff09<\/a><\/p>\n<p><a href=\"https:\/\/www.webcyou.com\/?p=7515\">Angular2\u306e\u59cb\u3081\u65b9\u3002Angular2 \u516c\u5f0f\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb \u2013 Multiple Components\uff08\u7c21\u5358\u306a\u548c\u8a33\uff09<\/a><\/p>\n<p><a href=\"https:\/\/www.webcyou.com\/?p=7512\">Angular2\u306e\u59cb\u3081\u65b9\u3002Angular2 \u516c\u5f0f\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb \u2013 Master\/Detail\uff08\u7c21\u5358\u306a\u548c\u8a33\uff09<\/a><\/p>\n<p><a href=\"https:\/\/www.webcyou.com\/?p=7507\">Angular2\u306e\u59cb\u3081\u65b9\u3002Angular2 \u516c\u5f0f\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb \u2013 SETUP FOR LOCAL DEVELOPMENT\uff08\u7c21\u5358\u306a\u548c\u8a33\uff09Angular2\u306e\u59cb\u3081\u65b9\u3002Angular2 \u516c\u5f0f\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb \u2013 Introduction\uff08\u7c21\u5358\u306a\u548c\u8a33\uff09<\/a><\/p>\n<p><a href=\"https:\/\/www.webcyou.com\/?p=7510\">Angular2\u306e\u59cb\u3081\u65b9\u3002Angular2 \u516c\u5f0f\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb \u2013 The Hero Editor\uff08\u7c21\u5358\u306a\u548c\u8a33\uff09<\/a><\/p>\n<p>Angular\u306eHTTP\u30b5\u30fc\u30d3\u30b9\u3092\u4f7f\u7528\u3059\u308b\u3088\u3046\u306b\u30b5\u30fc\u30d3\u30b9\u3068\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3092\u5909\u63db\u3057\u307e\u3059\u3002<\/p>\n<p>\u3053\u306e\u30da\u30fc\u30b8\u3067\u306f\u3001\u6b21\u306e\u70b9\u3092\u6539\u5584\u3057\u307e\u3059\u3002<\/p>\n<p>\u30fb\u30d2\u30fc\u30ed\u30fc\u30c7\u30fc\u30bf\u3092\u30b5\u30fc\u30d0\u30fc\u304b\u3089\u53d6\u5f97\u3057\u307e\u3059\u3002<\/p>\n<p>\u30fb\u4e3b\u4eba\u516c\u306e\u540d\u524d\u3092\u8ffd\u52a0\u3001\u7de8\u96c6\u3001\u524a\u9664\u3067\u304d\u308b\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n<p>\u30fb\u5909\u66f4\u3092\u30b5\u30fc\u30d0\u30fc\u306b\u4fdd\u5b58\u3057\u307e\u3059\u3002<\/p>\n<p>\u3042\u306a\u305f\u306f\u3001\u30ea\u30e2\u30fc\u30c8\u30b5\u30fc\u30d0\u30fc\u306eWeb API\u306b\u5bfe\u5fdc\u3059\u308bHTTP\u547c\u3073\u51fa\u3057\u3092\u884c\u3046\u3088\u3046\u306b\u30a2\u30d7\u30ea\u3092\u6559\u3048\u307e\u3059\u3002<\/p>\n<p>\u3053\u306e\u30da\u30fc\u30b8\u304c\u7d42\u4e86\u3057\u305f\u3089\u3001\u30a2\u30d7\u30ea\u306f\u3053\u306e <a href=\"https:\/\/angular.io\/resources\/live-examples\/toh-6\/ts\/eplnkr.html\" target=\"_blank\">live example<\/a> \/ <a href=\"https:\/\/angular.io\/resources\/zips\/toh-6\/toh-6.zip\" target=\"_blank\">downloadable example.<\/a>\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h4>Where you left off<\/h4>\n<p>\u524d\u306e\u30da\u30fc\u30b8\u3067\u306f\u3001\u30c0\u30c3\u30b7\u30e5\u30dc\u30fc\u30c9\u3068\u56fa\u5b9a\u30d2\u30fc\u30ed\u30fc\u30ea\u30b9\u30c8\u306e\u9593\u3092\u30ca\u30d3\u30b2\u30fc\u30c8\u3057\u3001\u9078\u629e\u3055\u308c\u305f\u30d2\u30fc\u30ed\u30fc\u3092\u9014\u4e2d\u3067\u7de8\u96c6\u3059\u308b\u65b9\u6cd5\u3092\u5b66\u3073\u307e\u3057\u305f\u3002\u305d\u308c\u304c\u3053\u306e\u30da\u30fc\u30b8\u306e\u51fa\u767a\u70b9\u3067\u3059\u3002<\/p>\n<h4>Keep the app transpiling and running<\/h4>\n<p>\u6b21\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5165\u529b\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">npm start<\/pre>\n<p>\u3053\u306e\u30b3\u30de\u30f3\u30c9\u306f\u3001&#8221;watch mode&#8221;\u3067\u3001TypeScript\u30b3\u30f3\u30d1\u30a4\u30e9\u3092\u5b9f\u884c\u3057\u3001\u30b3\u30fc\u30c9\u304c\u5909\u66f4\u3055\u308c\u305f\u3068\u304d\u306b\u81ea\u52d5\u7684\u306b\u518d\u30b3\u30f3\u30d1\u30a4\u30eb\u3057\u307e\u3059\u3002<\/p>\n<p>\u3053\u306e\u30b3\u30de\u30f3\u30c9\u306f\u3001\u30d6\u30e9\u30a6\u30b6\u3067\u30a2\u30d7\u30ea\u3092\u540c\u6642\u306b\u8d77\u52d5\u3057\u3001\u30b3\u30fc\u30c9\u304c\u5909\u66f4\u3055\u308c\u305f\u3068\u304d\u306b\u30d6\u30e9\u30a6\u30b6\u3092\u66f4\u65b0\u3057\u307e\u3059\u3002<\/p>\n<p>\u30d6\u30e9\u30a6\u30b6\u3092\u518d\u30b3\u30f3\u30d1\u30a4\u30eb\u307e\u305f\u306f\u66f4\u65b0\u3059\u308b\u305f\u3081\u306b\u4e00\u6642\u505c\u6b62\u3059\u308b\u3053\u3068\u306a\u304f\u3001\u30d2\u30fc\u30ed\u30fc\u306e\u30c4\u30a2\u30fc\u3092\u69cb\u7bc9\u3057\u7d9a\u3051\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<h4>Providing HTTP Services<\/h4>\n<p>HttpModule\u306fCore Angular\u30e2\u30b8\u30e5\u30fc\u30eb\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002 <\/p>\n<p>HttpModule\u306f\u3001Web\u30a2\u30af\u30bb\u30b9\u306b\u5bfe\u3059\u308bAngular\u306e\u30aa\u30d7\u30b7\u30e7\u30f3\u306e\u30a2\u30d7\u30ed\u30fc\u30c1\u3067\u3059\u3002<\/p>\n<p>\u3053\u308c\u306f\u3001@angular\/http \u3068\u547c\u3070\u308c\u308b\u500b\u5225\u306e\u30a2\u30c9\u30aa\u30f3\u30e2\u30b8\u30e5\u30fc\u30eb\u3068\u3057\u3066\u5b58\u5728\u3057\u3001Angular npm\u30d1\u30c3\u30b1\u30fc\u30b8\u306e\u4e00\u90e8\u3068\u3057\u3066\u5225\u306e\u30b9\u30af\u30ea\u30d7\u30c8\u30d5\u30a1\u30a4\u30eb\u306b\u540c\u68b1\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>systemjs.config\u306f\u5fc5\u8981\u306a\u3068\u304d\u306b\u305d\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u30ed\u30fc\u30c9\u3059\u308b\u3088\u3046\u306b\u8a2d\u5b9a\u3057\u3066\u3044\u308b\u306e\u3067\u3001 @angular\/http\u304b\u3089\u30a4\u30f3\u30dd\u30fc\u30c8\u3059\u308b\u6e96\u5099\u306f\u6574\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<h5>Register for HTTP services<\/h5>\n<p>\u3053\u306e\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306fAngular http\u30b5\u30fc\u30d3\u30b9\u306b\u4f9d\u5b58\u3057\u307e\u3059\u3002<\/p>\n<p>\u3053\u308c\u306f\u4ed6\u306e\u30b5\u30dd\u30fc\u30c8\u30b5\u30fc\u30d3\u30b9\u306b\u4f9d\u5b58\u3057\u307e\u3059\u3002 <\/p>\n<p>@angular\/http\u30e9\u30a4\u30d6\u30e9\u30ea\u306eHttpModule\u306f\u3001\u30d7\u30ed\u30d0\u30a4\u30c0\u306b\u5b8c\u5168\u306aHTTP\u30b5\u30fc\u30d3\u30b9\u306e\u30bb\u30c3\u30c8\u3092\u4fdd\u6301\u3057\u307e\u3059\u3002<\/p>\n<p>\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u3069\u3053\u304b\u3089\u3067\u3082\u3053\u308c\u3089\u306e\u30b5\u30fc\u30d3\u30b9\u306b\u30a2\u30af\u30bb\u30b9\u3067\u304d\u308b\u3088\u3046\u306b\u3059\u308b\u306b\u306f\u3001HttpModule\u3092AppModule\u306e\u30a4\u30f3\u30dd\u30fc\u30c8\u30ea\u30b9\u30c8\u306b\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n<p><strong>src\/app\/app.module.ts (v1)<\/strong><\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">import { NgModule }      from '@angular\/core';\r\nimport { BrowserModule } from '@angular\/platform-browser';\r\nimport { FormsModule }   from '@angular\/forms';\r\nimport { HttpModule }    from '@angular\/http';\r\nimport { AppRoutingModule } from '.\/app-routing.module';\r\nimport { AppComponent }         from '.\/app.component';\r\nimport { DashboardComponent }   from '.\/dashboard.component';\r\nimport { HeroesComponent }      from '.\/heroes.component';\r\nimport { HeroDetailComponent }  from '.\/hero-detail.component';\r\nimport { HeroService }          from '.\/hero.service';\r\n@NgModule({\r\n  imports: &#x5B;\r\n    BrowserModule,\r\n    FormsModule,\r\n    HttpModule,\r\n    AppRoutingModule\r\n  ],\r\n  declarations: &#x5B;\r\n    AppComponent,\r\n    DashboardComponent,\r\n    HeroDetailComponent,\r\n    HeroesComponent,\r\n  ],\r\n  providers: &#x5B; HeroService ],\r\n  bootstrap: &#x5B; AppComponent ]\r\n})\r\nexport class AppModule { }<\/pre>\n<p>\u30eb\u30fc\u30c8NgModule AppModule\u306e\u30a4\u30f3\u30dd\u30fc\u30c8\u914d\u5217\u306e\u4e00\u90e8\u3068\u3057\u3066HttpModule\u3082\u63d0\u4f9b\u3059\u308b\u3053\u3068\u306b\u6ce8\u610f\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<h4>Simulate the web API<\/h4>\n<p>\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u5168\u4f53\u306e\u30b5\u30fc\u30d3\u30b9\u3092\u30eb\u30fc\u30c8AppModule\u30d7\u30ed\u30d0\u30a4\u30c0\u306b\u767b\u9332\u3059\u308b\u3053\u3068\u3092\u304a\u52e7\u3081\u3057\u307e\u3059\u3002<\/p>\n<p>\u30d2\u30fc\u30ed\u30fc\u30c7\u30fc\u30bf\u306e\u30ea\u30af\u30a8\u30b9\u30c8\u3092\u51e6\u7406\u3067\u304d\u308bWeb\u30b5\u30fc\u30d0\u30fc\u304c\u306a\u3051\u308c\u3070\u3001HTTP\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u306f\u30e2\u30c3\u30af\u30b5\u30fc\u30d3\u30b9\uff08\u30e1\u30e2\u30ea\u5185Web API\uff09\u304b\u3089\u30c7\u30fc\u30bf\u3092\u30d5\u30a7\u30c3\u30c1\u3057\u3066\u4fdd\u5b58\u3057\u307e\u3059\u3002<\/p>\n<p>src\/app\/app.module.ts\u3092\u30e2\u30c3\u30af\u30b5\u30fc\u30d3\u30b9\u3092\u4f7f\u7528\u3059\u308b\u3053\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u3067\u66f4\u65b0\u3057\u3066\u304f\u3060\u3055\u3044\uff1a<\/p>\n<p><strong>src\/app\/app.module.ts (v2)<\/strong><\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">import { NgModule }      from '@angular\/core';\r\nimport { BrowserModule } from '@angular\/platform-browser';\r\nimport { FormsModule }   from '@angular\/forms';\r\nimport { HttpModule }    from '@angular\/http';\r\n\r\nimport { AppRoutingModule } from '.\/app-routing.module';\r\n\r\n\/\/ Imports for loading & configuring the in-memory web api\r\nimport { InMemoryWebApiModule } from 'angular-in-memory-web-api';\r\nimport { InMemoryDataService }  from '.\/in-memory-data.service';\r\n\r\nimport { AppComponent }         from '.\/app.component';\r\nimport { DashboardComponent }   from '.\/dashboard.component';\r\nimport { HeroesComponent }      from '.\/heroes.component';\r\nimport { HeroDetailComponent }  from '.\/hero-detail.component';\r\nimport { HeroService }          from '.\/hero.service';\r\n\r\n@NgModule({\r\n  imports: &#x5B;\r\n    BrowserModule,\r\n    FormsModule,\r\n    HttpModule,\r\n    InMemoryWebApiModule.forRoot(InMemoryDataService),\r\n    AppRoutingModule\r\n  ],\r\n  declarations: &#x5B;\r\n    AppComponent,\r\n    DashboardComponent,\r\n    HeroDetailComponent,\r\n    HeroesComponent,\r\n  ],\r\n  providers: &#x5B; HeroService ],\r\n  bootstrap: &#x5B; AppComponent ]\r\n})\r\nexport class AppModule { }<\/pre>\n<p>\u5b9f\u969b\u306eAPI\u30b5\u30fc\u30d0\u30fc\u3092\u5fc5\u8981\u3068\u3059\u308b\u306e\u3067\u306f\u306a\u304f\u3001<a href=\"https:\/\/github.com\/angular\/in-memory-web-api\" target=\"_blank\">InMemoryWebApiModule<\/a>\u3092\u30e2\u30b8\u30e5\u30fc\u30eb\u306e\u30a4\u30f3\u30dd\u30fc\u30c8\u306b\u8ffd\u52a0\u3059\u308b\u3053\u3068\u3067\u30ea\u30e2\u30fc\u30c8\u30b5\u30fc\u30d0\u30fc\u3068\u306e\u901a\u4fe1\u3092\u30b7\u30df\u30e5\u30ec\u30fc\u30c8\u3057\u3001Http\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u306eXHR\u30d0\u30c3\u30af\u30a8\u30f3\u30c9\u30b5\u30fc\u30d3\u30b9\u3092\u30e1\u30e2\u30ea\u5185\u306e\u4ee3\u66ff\u65b9\u6cd5\u3067\u52b9\u679c\u7684\u306b\u7f6e\u304d\u63db\u3048\u307e\u3059\u3002<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">InMemoryWebApiModule.forRoot(InMemoryDataService),<\/pre>\n<p>forRoot\uff08\uff09\u8a2d\u5b9a\u30e1\u30bd\u30c3\u30c9\u306f\u3001\u30e1\u30e2\u30ea\u5185\u306e\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3092\u6e96\u5099\u3059\u308bInMemoryDataService\u30af\u30e9\u30b9\u3092\u53d6\u308a\u307e\u3059\u3002 <\/p>\n<p>app\u5185\u306e\u30d5\u30a1\u30a4\u30ebin-memory-data.service.ts\u3092\u6b21\u306e\u5185\u5bb9\u3067\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n<p><strong>src\/app\/in-memory-data.service.ts<\/strong><\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">import { InMemoryDbService } from 'angular-in-memory-web-api';\r\nexport class InMemoryDataService implements InMemoryDbService {\r\n  createDb() {\r\n    let heroes = &#x5B;\r\n      {id: 11, name: 'Mr. Nice'},\r\n      {id: 12, name: 'Narco'},\r\n      {id: 13, name: 'Bombasto'},\r\n      {id: 14, name: 'Celeritas'},\r\n      {id: 15, name: 'Magneta'},\r\n      {id: 16, name: 'RubberMan'},\r\n      {id: 17, name: 'Dynama'},\r\n      {id: 18, name: 'Dr IQ'},\r\n      {id: 19, name: 'Magma'},\r\n      {id: 20, name: 'Tornado'}\r\n    ];\r\n    return {heroes};\r\n  }\r\n}<\/pre>\n<p>\u3053\u306e\u30d5\u30a1\u30a4\u30eb\u306fmock-heroes.ts\u306b\u7f6e\u304d\u63db\u3048\u3089\u308c\u307e\u3057\u305f\u3002\u3053\u308c\u306f\u4eca\u3067\u3082\u5b89\u5168\u306b\u524a\u9664\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>&#8220;&#8220;&#8220;<br \/>\n\u30e1\u30e2\u30ea\u5185\u306eWeb API\u306f\u3001\u958b\u767a\u306e\u521d\u671f\u6bb5\u968e\u3084\u3053\u306e\u300c\u82f1\u96c4\u30c4\u30a2\u30fc\u300d\u306a\u3069\u306e\u30c7\u30e2\u30f3\u30b9\u30c8\u30ec\u30fc\u30b7\u30e7\u30f3\u306b\u306e\u307f\u5f79\u7acb\u3061\u307e\u3059\u3002<\/p>\n<p>\u3053\u306e\u30d0\u30c3\u30af\u30a8\u30f3\u30c9\u7f6e\u63db\u306e\u8a73\u7d30\u306b\u3064\u3044\u3066\u306f\u5fc3\u914d\u3057\u306a\u3044\u3067\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>\u3042\u306a\u305f\u306f\u672c\u5f53\u306eWeb API\u30b5\u30fc\u30d0\u30fc\u3092\u6301\u3063\u3066\u3044\u308b\u3068\u304d\u306b\u30b9\u30ad\u30c3\u30d7\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u30e1\u30e2\u30ea\u5185Web API\u306e\u8a73\u7d30\u306b\u3064\u3044\u3066\u306f\u3001\u300c<a href=\"https:\/\/angular.io\/docs\/ts\/latest\/guide\/server-communication.html#in-mem-web-api\" target=\"_blank\">HTTP Client<\/a>\u300d\u30da\u30fc\u30b8\u306e\u4ed8\u9332\u300c <a href=\"https:\/\/angular.io\/docs\/ts\/latest\/guide\/server-communication.html#in-mem-web-api\" target=\"_blank\">Appendix: Tour of Heroes in-memory web api<\/a>\u300d\u3092\u53c2\u7167\u3057\u3066\u304f\u3060\u3055\u3044\u3002<br \/>\n&#8220;&#8220;&#8220;<\/p>\n<h4>Heroes and HTTP<\/h4>\n<p>\u73fe\u5728\u306eHeroService\u5b9f\u88c5\u3067\u306f\u3001\u6a21\u64ec\u30d2\u30fc\u30ed\u30fc\u3067\u89e3\u6c7a\u3055\u308c\u305fPromise\u304c\u8fd4\u3055\u308c\u307e\u3059\u3002<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">getHeroes(): Promise&lt;Hero&#x5B;]&gt; {\r\n  return Promise.resolve(HEROES);\r\n}<\/pre>\n<p>\u5f7c\u306f\u975e\u540c\u671f\u64cd\u4f5c\u3067\u306a\u3051\u308c\u3070\u306a\u3089\u306a\u3044HTTP\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u3067\u30d2\u30fc\u30ed\u30fc\u3092\u6700\u7d42\u7684\u306b\u53d6\u5f97\u3059\u308b\u3053\u3068\u3092\u671f\u5f85\u3057\u3066\u5b9f\u88c5\u3055\u308c\u307e\u3057\u305f\u3002<\/p>\n<p>HTTP\u3092\u4f7f\u7528\u3059\u308b\u3088\u3046\u306bgetHeroes\uff08\uff09\u3092\u5909\u63db\u3057\u307e\u3059\u3002<\/p>\n<p><strong>src\/app\/hero.service.ts (updated getHeroes and new class members)<\/strong><\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">  private heroesUrl = 'api\/heroes';  \/\/ URL to web api\r\n\r\n  constructor(private http: Http) { }\r\n\r\n  getHeroes(): Promise&lt;Hero&#x5B;]&gt; {\r\n    return this.http.get(this.heroesUrl)\r\n               .toPromise()\r\n               .then(response =&gt; response.json().data as Hero&#x5B;])\r\n               .catch(this.handleError);\r\n  }\r\n\r\n  private handleError(error: any): Promise&lt;any&gt; {\r\n    console.error('An error occurred', error); \/\/ for demo purposes only\r\n    return Promise.reject(error.message || error);\r\n  }<\/pre>\n<p>\u6b21\u306e\u3088\u3046\u306b\u30a4\u30f3\u30dd\u30fc\u30c8\u6587\u3092\u66f4\u65b0\u3057\u307e\u3059\u3002<\/p>\n<p><strong>src\/app\/hero.service.ts (updated imports)<\/strong><\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">import { Injectable }    from '@angular\/core';\r\nimport { Headers, Http } from '@angular\/http';\r\n\r\nimport 'rxjs\/add\/operator\/toPromise';\r\n\r\nimport { Hero } from '.\/hero';<\/pre>\n<p>\u30d6\u30e9\u30a6\u30b6\u3092\u66f4\u65b0\u3057\u307e\u3059\u3002\u4e3b\u4eba\u516c\u306e\u30c7\u30fc\u30bf\u304c\u30e2\u30c3\u30af\u30b5\u30fc\u30d0\u30fc\u304b\u3089\u6b63\u5e38\u306b\u8aad\u307f\u8fbc\u307e\u308c\u308b\u306f\u305a\u3067\u3059\u3002<\/p>\n<h5>HTTP Promise<\/h5>\n<p>Angular http.get\u306f\u3001RxJS Observable\u3092\u8fd4\u3057\u307e\u3059\u3002<\/p>\n<p>Observables\u306f\u3001\u975e\u540c\u671f\u30c7\u30fc\u30bf\u30d5\u30ed\u30fc\u3092\u7ba1\u7406\u3059\u308b\u5f37\u529b\u306a\u65b9\u6cd5\u3067\u3059\u3002<\/p>\n<p>\u3053\u306e\u30da\u30fc\u30b8\u306e\u5f8c\u534a\u3067<a href=\"https:\/\/angular.io\/docs\/ts\/latest\/tutorial\/toh-pt6.html#observables\" target=\"_blank\">Observables<\/a>\u306b\u3064\u3044\u3066\u8aad\u3080\u3053\u3068\u306b\u3057\u307e\u3059\u3002<\/p>\n<p>\u4eca\u306e\u3068\u3053\u308d\u3001toPromise\u6f14\u7b97\u5b50\u3092\u4f7f\u7528\u3057\u3066Observable\u3092Promise\u306b\u5909\u63db\u3057\u307e\u3057\u305f\u3002<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">.toPromise()<\/pre>\n<p>Angular Observable\u306b\u306f\u3001toPromise\u6f14\u7b97\u5b50\u306f\u7528\u610f\u3055\u308c\u3066\u3044\u307e\u305b\u3093\u3002<\/p>\n<p>\u4fbf\u5229\u306a\u6a5f\u80fd\u3067\u3001Observable\u3092\u62e1\u5f35\u3059\u308btoPromise\u306e\u3088\u3046\u306a\u591a\u304f\u306e\u6f14\u7b97\u5b50\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u3053\u308c\u3089\u306e\u6a5f\u80fd\u3092\u4f7f\u7528\u3059\u308b\u306b\u306f\u3001\u6f14\u7b97\u5b50\u81ea\u4f53\u3092\u8ffd\u52a0\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u3053\u308c\u306fRxJS\u30e9\u30a4\u30d6\u30e9\u30ea\u304b\u3089\u6b21\u306e\u3088\u3046\u306b\u30a4\u30f3\u30dd\u30fc\u30c8\u3059\u308b\u306e\u3068\u540c\u3058\u304f\u3089\u3044\u7c21\u5358\u3067\u3059\uff1a<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">import 'rxjs\/add\/operator\/toPromise';<\/pre>\n<p>&#8220;&#8220;&#8220;<br \/>\n\u3053\u306e\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u306e\u5f8c\u534a\u3067\u306f\u3001\u6f14\u7b97\u5b50\u3092\u8ffd\u52a0\u3057\u3066\u3001\u305d\u308c\u3092\u884c\u3046\u5fc5\u8981\u304c\u3042\u308b\u7406\u7531\u3092\u5b66\u7fd2\u3057\u307e\u3059\u3002<br \/>\n&#8220;&#8220;&#8220;<\/p>\n<h5>Extracting the data in the then callback<\/h5>\n<p>Promise\u306ethen\uff08\uff09\u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u3067\u306f\u3001HTTP\u5fdc\u7b54\u306ejson\u30e1\u30bd\u30c3\u30c9\u3092\u547c\u3073\u51fa\u3057\u3066\u3001\u5fdc\u7b54\u5185\u306e\u30c7\u30fc\u30bf\u3092\u62bd\u51fa\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">.then(response =&gt; response.json().data as Hero&#x5B;])<\/pre>\n<p>\u30ec\u30b9\u30dd\u30f3\u30b9JSON\u306b\u306f\u3001\u547c\u3073\u51fa\u3057\u5143\u304c\u671b\u3080\u30d2\u30fc\u30ed\u30fc\u306e\u914d\u5217\u3092\u4fdd\u6301\u3059\u308b\u5358\u4e00\u306edata\u30d7\u30ed\u30d1\u30c6\u30a3\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u3057\u305f\u304c\u3063\u3066\u3001\u914d\u5217\u3092\u53d6\u5f97\u3057\u3001\u305d\u308c\u3092\u89e3\u6c7a\u3055\u308c\u305fPromise\u5024\u3068\u3057\u3066\u8fd4\u3057\u307e\u3059\u3002<\/p>\n<p>&#8220;&#8220;&#8220;<br \/>\n\u30b5\u30fc\u30d0\u30fc\u304c\u8fd4\u3059\u30c7\u30fc\u30bf\u306e\u5f62\u306b\u6ce8\u610f\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>\u3053\u306e\u7279\u5b9a\u306e\u30e1\u30e2\u30ea\u5185Web API\u306e\u4f8b\u306f\u3001data\u30d7\u30ed\u30d1\u30c6\u30a3\u3092\u6301\u3064\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u8fd4\u3057\u307e\u3059\u3002 <\/p>\n<p>API\u304c\u4f55\u304b\u3092\u8fd4\u3059\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002 Web API\u306b\u5408\u308f\u305b\u3066\u30b3\u30fc\u30c9\u3092\u8abf\u6574\u3057\u307e\u3059\u3002<br \/>\n&#8220;&#8220;&#8220;<\/p>\n<p>\u547c\u3073\u51fa\u3057\u5143\u306f\u3042\u306a\u305f\u304c\uff08\u30e2\u30c3\u30af\uff09\u30b5\u30fc\u30d0\u30fc\u304b\u3089\u30d2\u30fc\u30ed\u30fc\u3092\u53d6\u308a\u8fbc\u3093\u3060\u3053\u3068\u306b\u6c17\u4ed8\u304b\u306a\u3044\u3002<\/p>\n<p>\u305d\u308c\u306f\u524d\u3068\u540c\u3058\u3088\u3046\u306b\u3001heroes\u306ePromise\u3092\u53d7\u3051\u307e\u3059\u3002<\/p>\n<h5>Error Handling<\/h5>\n<p>getHeroes\uff08\uff09\u306e\u7d42\u4e86\u6642\u306b\u3001\u30b5\u30fc\u30d0\u30fc\u306e\u969c\u5bb3\u3092\u6355\u6349\u3057\u3066\u30a8\u30e9\u30fc\u30cf\u30f3\u30c9\u30e9\u306b\u6e21\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">.catch(this.handleError);<\/pre>\n<p>\u3053\u308c\u306f\u91cd\u8981\u306a\u30b9\u30c6\u30c3\u30d7\u3067\u3059\u3002 HTTP\u969c\u5bb3\u306f\u3001\u5236\u5fa1\u3067\u304d\u306a\u3044\u7406\u7531\u3067\u983b\u7e41\u306b\u767a\u751f\u3059\u308b\u305f\u3081\u3001\u4e88\u671f\u3057\u306a\u3051\u308c\u3070\u306a\u308a\u307e\u305b\u3093\u3002<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">private handleError(error: any): Promise&lt;any&gt; {\r\n  console.error('An error occurred', error); \/\/ for demo purposes only\r\n  return Promise.reject(error.message || error);\r\n}<\/pre>\n<p>\u3053\u306e\u30c7\u30e2\u30b5\u30fc\u30d3\u30b9\u3067\u306f\u3001\u30a8\u30e9\u30fc\u3092\u30b3\u30f3\u30bd\u30fc\u30eb\u306b\u8a18\u9332\u3057\u307e\u3059\u3002\u5b9f\u969b\u306b\u306f\u3001\u30b3\u30fc\u30c9\u306e\u30a8\u30e9\u30fc\u3092\u51e6\u7406\u3057\u307e\u3059\u3002\u30c7\u30e2\u306e\u305f\u3081\u306b\u3001\u3053\u308c\u306f\u52d5\u4f5c\u3057\u307e\u3059\u3002<\/p>\n<p>\u307e\u305f\u3001\u30b3\u30fc\u30c9\u306b\u306f\u3001\u62d2\u5426\u3055\u308c\u305f\u7d04\u675f\u4e8b\u3067\u767a\u547c\u8005\u306b\u30a8\u30e9\u30fc\u304c\u542b\u307e\u308c\u3066\u3044\u308b\u305f\u3081\u3001\u767a\u547c\u8005\u306f\u9069\u5207\u306a\u30a8\u30e9\u30fc\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u30e6\u30fc\u30b6\u306b\u8868\u793a\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3002<\/p>\n<h5>Get hero by id<\/h5>\n<p>HeroDetailComponent\u304cHeroService\u306b\u30d2\u30fc\u30ed\u30fc\u3092\u30d5\u30a7\u30c3\u30c1\u3059\u308b\u3088\u3046\u306b\u8981\u6c42\u3059\u308b\u3068\u3001HeroService\u306f\u73fe\u5728\u3001\u4e00\u81f4\u3059\u308bID\u3092\u6301\u3064\u30d2\u30fc\u30ed\u30fc\u3068\u30d5\u30a3\u30eb\u30bf\u3092\u3059\u3079\u3066\u30d5\u30a7\u30c3\u30c1\u3057\u307e\u3059\u3002<\/p>\n<p>\u305d\u308c\u306f\u30b7\u30df\u30e5\u30ec\u30fc\u30b7\u30e7\u30f3\u3067\u306f\u554f\u984c\u3042\u308a\u307e\u305b\u3093\u304c\u3001\u5b9f\u969b\u306e\u30b5\u30fc\u30d0\u30fc\u306b\u3059\u3079\u3066\u306e\u30d2\u30fc\u30ed\u30fc\u3092\u6c42\u3081\u308b\u306e\u306f\u7121\u99c4\u3067\u3059\u3002<\/p>\n<p>\u307b\u3068\u3093\u3069\u306eWeb API\u306f\u3001api\/hero\/\uff1aid\u306e\u5f62\u5f0f\uff08api\/hero\/11\u306a\u3069\uff09\u3067get-by-id\u30ea\u30af\u30a8\u30b9\u30c8\u3092\u30b5\u30dd\u30fc\u30c8\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>HeroService.getHero\u30e1\u30bd\u30c3\u30c9\u3092\u66f4\u65b0\u3057\u3066\u3001get-by-id\u30ea\u30af\u30a8\u30b9\u30c8\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<p><strong>src\/app\/hero.service.ts (getHero)<\/strong><\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">getHero(id: number): Promise&lt;Hero&gt; {\r\n  const url = `${this.heroesUrl}\/${id}`;\r\n  return this.http.get(url)\r\n    .toPromise()\r\n    .then(response =&gt; response.json().data as Hero)\r\n    .catch(this.handleError);\r\n}<\/pre>\n<p>\u3053\u306e\u30ea\u30af\u30a8\u30b9\u30c8\u306fgetHeroes\u3068\u307b\u3068\u3093\u3069\u540c\u3058\u3067\u3059\u3002 URL\u306e\u30d2\u30fc\u30ed\u30fcID\u306f\u3001\u30b5\u30fc\u30d0\u30fc\u304c\u66f4\u65b0\u3059\u308b\u30d2\u30fc\u30ed\u30fc\u3092\u8b58\u5225\u3057\u307e\u3059\u3002<\/p>\n<p>\u307e\u305f\u3001\u5fdc\u7b54\u306e\u30c7\u30fc\u30bf\u306f\u914d\u5217\u3067\u306f\u306a\u304f\u5358\u4e00\u306e\u30d2\u30fc\u30ed\u30fc\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3067\u3059\u3002<\/p>\n<h5>Unchanged getHeroes API<\/h5>\n<p>getHeroes\uff08\uff09\u3068getHero\uff08\uff09\u306b\u5bfe\u3057\u3066\u5185\u90e8\u7684\u306a\u5909\u66f4\u3092\u884c\u3063\u305f\u306b\u3082\u304b\u304b\u308f\u3089\u305a\u3001\u30d1\u30d6\u30ea\u30c3\u30af\u30b7\u30b0\u30cd\u30c1\u30e3\u306f\u5909\u66f4\u3055\u308c\u307e\u305b\u3093\u3067\u3057\u305f\u3002<\/p>\n<p>\u4e21\u65b9\u306e\u65b9\u6cd5\u304b\u3089Promise\u3092\u8fd4\u3057\u307e\u3059\u3002\u305d\u308c\u3089\u3092\u547c\u3073\u51fa\u3059\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3092\u66f4\u65b0\u3059\u308b\u5fc5\u8981\u306f\u3042\u308a\u307e\u305b\u3093\u3002<\/p>\n<p>\u4eca\u5ea6\u306f\u30d2\u30fc\u30ed\u30fc\u306e\u4f5c\u6210\u3068\u524a\u9664\u306e\u6a5f\u80fd\u3092\u8ffd\u52a0\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<h4>Updating hero details<\/h4>\n<p>\u30d2\u30fc\u30ed\u30fc\u306e\u8a73\u7d30\u30d3\u30e5\u30fc\u3067\u30d2\u30fc\u30ed\u30fc\u306e\u540d\u524d\u3092\u7de8\u96c6\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>\u5165\u529b\u3059\u308b\u3068\u3001\u30d2\u30ed\u306e\u540d\u524d\u304c\u30d3\u30e5\u30fc\u306e\u898b\u51fa\u3057\u3067\u66f4\u65b0\u3055\u308c\u307e\u3059\u3002\u3057\u304b\u3057\u3001[\u623b\u308b]\u30dc\u30bf\u30f3\u3092\u30af\u30ea\u30c3\u30af\u3059\u308b\u3068\u3001\u5909\u66f4\u304c\u5931\u308f\u308c\u307e\u3059\u3002<\/p>\n<p>\u66f4\u65b0\u306f\u4ee5\u524d\u306f\u5931\u308f\u308c\u3066\u3044\u307e\u305b\u3093\u3067\u3057\u305f\u3002\u4f55\u304c\u5909\u308f\u3063\u305f\u306e\uff1f\u30a2\u30d7\u30ea\u304c\u6a21\u64ec\u30d2\u30fc\u30ed\u30fc\u306e\u30ea\u30b9\u30c8\u3092\u4f7f\u7528\u3057\u305f\u3068\u304d\u3001\u30a2\u30d7\u30ea\u5168\u4f53\u306e\u5171\u6709\u30ea\u30b9\u30c8\u5185\u306e\u30d2\u30fc\u30ed\u30fc\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b\u66f4\u65b0\u304c\u76f4\u63a5\u9069\u7528\u3055\u308c\u307e\u3057\u305f\u3002<\/p>\n<p>\u30b5\u30fc\u30d0\u30fc\u304b\u3089\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3059\u308b\u3088\u3046\u306b\u306a\u3063\u305f\u306e\u3067\u3001\u5909\u66f4\u3092\u7dad\u6301\u3059\u308b\u306b\u306f\u3001\u30b5\u30fc\u30d0\u30fc\u306b\u66f8\u304d\u623b\u3059\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<h5>Add the ability to save hero details<\/h5>\n<p>\u30d2\u30fc\u30ed\u30fc\u8a73\u7d30\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u306e\u6700\u5f8c\u306b\u3001save\u3068\u3044\u3046\u540d\u524d\u306e\u65b0\u3057\u3044\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u30e1\u30bd\u30c3\u30c9\u3092\u547c\u3073\u51fa\u3059click\u30a4\u30d9\u30f3\u30c8\u30d0\u30a4\u30f3\u30c7\u30a3\u30f3\u30b0\u3092\u542b\u3080\u4fdd\u5b58\u30dc\u30bf\u30f3\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n<p><strong>src\/app\/hero-detail.component.html (save)<\/strong><\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">&lt;button (click)=&quot;save()&quot;&gt;Save&lt;\/button&gt;<\/pre>\n<p>\u30d2\u30fc\u30ed\u30fc\u30b5\u30fc\u30d3\u30b9\u306e\u66f4\u65b0\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u7528\u3057\u3066\u30d2\u30fc\u30ed\u30fc\u540d\u306e\u5909\u66f4\u3092\u4fdd\u6301\u3057\u3066\u304b\u3089\u3001\u524d\u306e\u30d3\u30e5\u30fc\u306b\u623b\u308b\u3001\u6b21\u306e\u4fdd\u5b58\u30e1\u30bd\u30c3\u30c9\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n<p><strong>src\/app\/hero-detail.component.ts (save)<\/strong><\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">save(): void {\r\n  this.heroService.update(this.hero)\r\n    .then(() =&gt; this.goBack());\r\n}<\/pre>\n<h5>Add a hero service update method<\/h5>\n<p><strong>src\/app\/hero.service.ts (update)<\/strong><\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">private headers = new Headers({'Content-Type': 'application\/json'});\r\n\r\nupdate(hero: Hero): Promise&lt;Hero&gt; {\r\n  const url = `${this.heroesUrl}\/${hero.id}`;\r\n  return this.http\r\n    .put(url, JSON.stringify(hero), {headers: this.headers})\r\n    .toPromise()\r\n    .then(() =&gt; hero)\r\n    .catch(this.handleError);\r\n}<\/pre>\n<p>\u30b5\u30fc\u30d0\u30fc\u304c\u66f4\u65b0\u3059\u308b\u30d2\u30fc\u30ed\u30fc\u3092\u7279\u5b9a\u3059\u308b\u305f\u3081\u306b\u3001\u30d2\u30fc\u30ed\u30fcID\u304cURL\u306b\u30a8\u30f3\u30b3\u30fc\u30c9\u3055\u308c\u307e\u3059\u3002 <\/p>\n<p>put\uff08\uff09\u672c\u6587\u306f\u3001JSON.stringify\u3092\u547c\u3073\u51fa\u3057\u3066\u53d6\u5f97\u3057\u305f\u30d2\u30fc\u30ed\u30fc\u306eJSON\u6587\u5b57\u5217\u30a8\u30f3\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0\u3067\u3059\u3002<\/p>\n<p>\u30dc\u30c7\u30a3\u30b3\u30f3\u30c6\u30f3\u30c4\u30bf\u30a4\u30d7\uff08application \/ json\uff09\u306f\u3001\u30ea\u30af\u30a8\u30b9\u30c8\u30d8\u30c3\u30c0\u3067\u8b58\u5225\u3055\u308c\u307e\u3059\u3002<\/p>\n<p>\u30d6\u30e9\u30a6\u30b6\u3092\u66f4\u65b0\u3057\u3001\u30d2\u30fc\u30ed\u30fc\u540d\u3092\u5909\u66f4\u3057\u3066\u5909\u66f4\u3092\u4fdd\u5b58\u3057\u3001\u30d6\u30e9\u30a6\u30b6\u306e[\u623b\u308b]\u30dc\u30bf\u30f3\u3092\u30af\u30ea\u30c3\u30af\u3057\u307e\u3059\u3002\u5909\u66f4\u306f\u4eca\u3082\u7d9a\u304f\u306f\u305a\u3067\u3059\u3002<\/p>\n<h4>Add the ability to add heroes<\/h4>\n<p>\u4e3b\u4eba\u516c\u3092\u8ffd\u52a0\u3059\u308b\u306b\u306f\u3001\u4e3b\u4eba\u516c\u306e\u540d\u524d\u304c\u5fc5\u8981\u3067\u3059\u3002<\/p>\n<p>\u8ffd\u52a0\u30dc\u30bf\u30f3\u3068\u30da\u30a2\u306b\u306a\u3063\u305f\u5165\u529b\u8981\u7d20\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u30d2\u30fc\u30ed\u30fc\u30ba\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306eHTML\u306b\u3001\u898b\u51fa\u3057\u306e\u76f4\u5f8c\u306b\u4ee5\u4e0b\u3092\u633f\u5165\u3057\u307e\u3059\u3002<\/p>\n<p><strong>src\/app\/heroes.component.html (add)<\/strong><\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">&lt;div&gt;\r\n  &lt;label&gt;Hero name:&lt;\/label&gt; &lt;input #heroName \/&gt;\r\n  &lt;button (click)=&quot;add(heroName.value); heroName.value=''&quot;&gt;\r\n    Add\r\n  &lt;\/button&gt;\r\n&lt;\/div&gt;<\/pre>\n<p>\u30af\u30ea\u30c3\u30af\u30a4\u30d9\u30f3\u30c8\u306b\u5fdc\u3058\u3066\u3001\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306e\u30af\u30ea\u30c3\u30af\u30cf\u30f3\u30c9\u30e9\u3092\u547c\u3073\u51fa\u3057\u3001\u5165\u529b\u30d5\u30a3\u30fc\u30eb\u30c9\u3092\u30af\u30ea\u30a2\u3057\u3066\u5225\u306e\u540d\u524d\u306e\u6e96\u5099\u304c\u6574\u3046\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n<p><strong>src\/app\/heroes.component.ts (add)<\/strong><\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">add(name: string): void {\r\n  name = name.trim();\r\n  if (!name) { return; }\r\n  this.heroService.create(name)\r\n    .then(hero =&gt; {\r\n      this.heroes.push(hero);\r\n      this.selectedHero = null;\r\n    });\r\n}<\/pre>\n<p>\u6307\u5b9a\u3055\u308c\u305f\u540d\u524d\u304c\u7a7a\u3067\u306a\u3044\u5834\u5408\u3001\u30cf\u30f3\u30c9\u30e9\u306f\u6307\u5b9a\u3055\u308c\u305f\u30d2\u30fc\u30ed\u30fc\u306e\u4f5c\u6210\u3092\u30d2\u30fc\u30ed\u30fc\u30b5\u30fc\u30d3\u30b9\u306b\u59d4\u4efb\u3057\u3001\u6b21\u306b\u65b0\u3057\u3044\u30d2\u30fc\u30ed\u30fc\u3092\u914d\u5217\u306b\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n<p>HeroService\u30af\u30e9\u30b9\u306bcreate\u30e1\u30bd\u30c3\u30c9\u3092\u5b9f\u88c5\u3057\u307e\u3059\u3002<\/p>\n<p><strong>src\/app\/hero.service.ts (create)<\/strong><\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">create(name: string): Promise&lt;Hero&gt; {\r\n  return this.http\r\n    .post(this.heroesUrl, JSON.stringify({name: name}), {headers: this.headers})\r\n    .toPromise()\r\n    .then(res =&gt; res.json().data as Hero)\r\n    .catch(this.handleError);\r\n}<\/pre>\n<p>\u30d6\u30e9\u30a6\u30b6\u3092\u30ea\u30d5\u30ec\u30c3\u30b7\u30e5\u3057\u3066\u3044\u304f\u3064\u304b\u306e\u30d2\u30fc\u30ed\u30fc\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<h4>Add the ability to delete a hero<\/h4>\n<p>\u4e3b\u4eba\u516c\u306e\u30d3\u30e5\u30fc\u306e\u5404\u30d2\u30fc\u30ed\u30fc\u306b\u306f\u524a\u9664\u30dc\u30bf\u30f3\u304c\u5fc5\u8981\u3067\u3059\u3002<\/p>\n<p>heroes\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306eHTML\u306b\u3001\u7e70\u308a\u8fd4\u3057\u305f &lt;li&gt;\u30bf\u30b0\u306e\u30d2\u30fc\u30ed\u30fc\u540d\u306e\u5f8c\u306b\u6b21\u306e\u30dc\u30bf\u30f3\u8981\u7d20\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">&lt;button class=&quot;delete&quot;\r\n  (click)=&quot;delete(hero); $event.stopPropagation()&quot;&gt;x&lt;\/button&gt;<\/pre>\n<p>&lt;li&gt;\u8981\u7d20\u306f\u6b21\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><strong>src\/app\/heroes.component.html (li-element)<\/strong><\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">&lt;li *ngFor=&quot;let hero of heroes&quot; (click)=&quot;onSelect(hero)&quot; &#x5B;class.selected]=&quot;hero === selectedHero&quot;&gt;\r\n  &lt;span class=&quot;badge&quot;&gt;{{hero.id}}&lt;\/span&gt;\r\n  &lt;span&gt;{{hero.name}}&lt;\/span&gt;\r\n  &lt;button class=&quot;delete&quot; (click)=&quot;delete(hero); $event.stopPropagation()&quot;&gt;x&lt;\/button&gt;\r\n&lt;\/li&gt;<\/pre>\n<p>\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306edelete\uff08\uff09\u30e1\u30bd\u30c3\u30c9\u3092\u547c\u3073\u51fa\u3059\u3053\u3068\u306b\u52a0\u3048\u3066\u3001\u524a\u9664\u30dc\u30bf\u30f3\u306e\u30af\u30ea\u30c3\u30af\u30cf\u30f3\u30c9\u30e9\u30b3\u30fc\u30c9\u306f\u30af\u30ea\u30c3\u30af\u30a4\u30d9\u30f3\u30c8\u306e\u4f1d\u64ad\u3092\u505c\u6b62\u3057\u307e\u3059\u3002<\/p>\n<p>\u305d\u306e\u305f\u3081\u3001<\/p>\n<li>\u30af\u30ea\u30c3\u30af\u30cf\u30f3\u30c9\u30e9\u304c\u30c8\u30ea\u30ac\u3055\u308c\u308b\u3053\u3068\u306f\u671b\u307e\u3057\u304f\u3042\u308a\u307e\u305b\u3093\u3002\u524a\u9664\u3057\u307e\u3059\u3002\n<p>delete\uff08\uff09\u30cf\u30f3\u30c9\u30e9\u306e\u30ed\u30b8\u30c3\u30af\u306f\u3084\u3084\u96e3\u89e3\u3067\u3059\uff1a<\/p>\n<p><strong>src\/app\/heroes.component.ts (delete)<\/strong><\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">delete(hero: Hero): void {\r\n  this.heroService\r\n      .delete(hero.id)\r\n      .then(() =&gt; {\r\n        this.heroes = this.heroes.filter(h =&gt; h !== hero);\r\n        if (this.selectedHero === hero) { this.selectedHero = null; }\r\n      });\r\n}<\/pre>\n<p>\u3082\u3061\u308d\u3093\u3001\u4e3b\u4eba\u516c\u306e\u524a\u9664\u3092\u4e3b\u4eba\u516c\u306e\u30b5\u30fc\u30d3\u30b9\u306b\u59d4\u4efb\u3057\u307e\u3059\u304c\u3001\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306f\u8868\u793a\u3092\u66f4\u65b0\u3059\u308b\u8cac\u4efb\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u524a\u9664\u3055\u308c\u305f\u4e3b\u4eba\u516c\u3092\u524a\u9664\u3057\u3001\u5fc5\u8981\u306b\u5fdc\u3058\u3066\u9078\u629e\u3057\u305f\u30d2\u30fc\u30ed\u30fc\u3092\u30ea\u30bb\u30c3\u30c8\u3057\u307e\u3059\u3002<\/p>\n<p>\u30d2\u30fc\u30ed\u30fc\u30a8\u30f3\u30c8\u30ea\u306e\u53f3\u7aef\u306b\u524a\u9664\u30dc\u30bf\u30f3\u3092\u914d\u7f6e\u3059\u308b\u306b\u306f\u3001\u3053\u306e\u8ffd\u52a0\u306eCSS\u3092\u8ffd\u52a0\u3057\u307e\u3059\uff1a<\/p>\n<p><strong>src\/app\/heroes.component.css (additions)<\/strong><\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">button.delete {\r\n  float:right;\r\n  margin-top: 2px;\r\n  margin-right: .8em;\r\n  background-color: gray !important;\r\n  color:white;\r\n}<\/pre>\n<h5>Hero service delete() method<\/h5>\n<p>\u30d2\u30fc\u30ed\u30fc\u30b5\u30fc\u30d3\u30b9\u306edelete\uff08\uff09\u30e1\u30bd\u30c3\u30c9\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002\u3053\u306e\u30e1\u30bd\u30c3\u30c9\u306fdelete\uff08\uff09HTTP\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u7528\u3057\u3066\u3001\u30d2\u30fc\u30ed\u30fc\u3092\u30b5\u30fc\u30d0\u30fc\u304b\u3089\u524a\u9664\u3057\u307e\u3059\u3002<\/p>\n<p><strong>src\/app\/hero.service.ts (delete)<\/strong><\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">delete(id: number): Promise&lt;void&gt; {\r\n  const url = `${this.heroesUrl}\/${id}`;\r\n  return this.http.delete(url, {headers: this.headers})\r\n    .toPromise()\r\n    .then(() =&gt; null)\r\n    .catch(this.handleError);\r\n}<\/pre>\n<p>\u30d6\u30e9\u30a6\u30b6\u3092\u66f4\u65b0\u3057\u3066\u3001\u65b0\u3057\u3044\u524a\u9664\u6a5f\u80fd\u3092\u8a66\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<h4>Observables<\/h4>\n<p>\u5404Http\u30b5\u30fc\u30d3\u30b9\u30e1\u30bd\u30c3\u30c9\u306f\u3001Observable of HTTP Response\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u8fd4\u3057\u307e\u3059\u3002<\/p>\n<p>HeroService\u306fObservable\u3092Promise\u306b\u5909\u63db\u3057\u3001\u547c\u3073\u51fa\u3057\u5143\u306b\u7d04\u675f\u3092\u8fd4\u3057\u307e\u3059\u3002\u3053\u306e\u30bb\u30af\u30b7\u30e7\u30f3\u3067\u306f\u3001Observable\u3092\u3069\u306e\u3088\u3046\u306b\u3001\u3044\u3064\u3001\u306a\u305c\u3001\u306a\u305c\u76f4\u63a5\u8fd4\u3059\u306e\u304b\u3092\u793a\u3057\u307e\u3059\u3002<\/p>\n<h5>Background<\/h5>\n<p>Observable\u306f\u914d\u5217\u306e\u3088\u3046\u306a\u6f14\u7b97\u5b50\u3067\u51e6\u7406\u3067\u304d\u308b\u30a4\u30d9\u30f3\u30c8\u306e\u30b9\u30c8\u30ea\u30fc\u30e0\u3067\u3059\u3002<\/p>\n<p>Angular core\u306f\u3001observables\u3092\u57fa\u672c\u7684\u306b\u30b5\u30dd\u30fc\u30c8\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u958b\u767a\u8005\u306f\u3001RxJS\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u6f14\u7b97\u5b50\u3068\u62e1\u5f35\u6a5f\u80fd\u3092\u4f7f\u7528\u3057\u3066\u305d\u306e\u30b5\u30dd\u30fc\u30c8\u3092\u5f37\u5316\u3057\u307e\u3059\u3002\u3042\u306a\u305f\u306f\u3059\u3050\u306b\u8868\u793a\u3055\u308c\u307e\u3059\u3002<\/p>\n<p>HeroService\u306f\u3001toPromise\u6f14\u7b97\u5b50\u3092http.get\uff08\uff09\u306eObservable\u7d50\u679c\u306b\u30c1\u30a7\u30fc\u30f3\u3059\u308b\u3053\u3068\u3092\u601d\u3044\u51fa\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>\u305d\u306e\u30aa\u30da\u30ec\u30fc\u30bf\u306fObservable\u3092Promise\u306b\u5909\u63db\u3057\u3001\u305d\u306e\u7d04\u675f\u3092\u547c\u3073\u51fa\u3057\u5143\u306b\u8fd4\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u30d7\u30ed\u30df\u30b9\u3078\u306e\u5909\u63db\u306f\u3001\u3057\u3070\u3057\u3070\u826f\u3044\u9078\u629e\u3067\u3059\u3002<\/p>\n<p>\u901a\u5e38\u3001http.get\uff08\uff09\u306b\u30c7\u30fc\u30bf\u306e\u5358\u4e00\u306e\u30c1\u30e3\u30f3\u30af\u3092\u30d5\u30a7\u30c3\u30c1\u3059\u308b\u3088\u3046\u306b\u4f9d\u983c\u3057\u307e\u3059\u3002\u30c7\u30fc\u30bf\u3092\u53d7\u4fe1\u3059\u308b\u3068\u3001\u5b8c\u4e86\u3067\u3059\u3002\u547c\u3073\u51fa\u3057\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306f\u3001Promise\u306e\u5f62\u5f0f\u3067\u5358\u4e00\u306e\u7d50\u679c\u3092\u7c21\u5358\u306b\u6d88\u8cbb\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u3057\u304b\u3057\u3001\u8981\u6c42\u306f\u5fc5\u305a\u3057\u3082\u4e00\u5ea6\u3057\u304b\u884c\u308f\u308c\u307e\u305b\u3093\u3002\u30b5\u30fc\u30d0\u30fc\u304c\u6700\u521d\u306e\u8981\u6c42\u306b\u5fdc\u7b54\u3059\u308b\u524d\u306b\u30011\u3064\u306e\u8981\u6c42\u3092\u958b\u59cb\u3057\u3066\u53d6\u308a\u6d88\u3057\u3001\u5225\u306e\u8981\u6c42\u3092\u884c\u3046\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002 <\/p>\n<p>request-cancel-new-request\u30b7\u30fc\u30b1\u30f3\u30b9\u306f\u3001\u95a2\u6570Promise\uff08\uff09{[native code]}\u3067\u5b9f\u88c5\u3059\u308b\u306e\u306f\u56f0\u96e3\u3067\u3059\u304c\u3001s\u3067\u306f\u7c21\u5358\u3067\u3059\u3002<\/p>\n<h5>Add the ability to search by name<\/h5>\n<p><strong>src\/app\/hero-search.service.ts<\/strong><\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">import { Injectable } from '@angular\/core';\r\nimport { Http }       from '@angular\/http';\r\nimport { Observable }     from 'rxjs\/Observable';\r\nimport 'rxjs\/add\/operator\/map';\r\nimport { Hero }           from '.\/hero';\r\n@Injectable()\r\nexport class HeroSearchService {\r\n  constructor(private http: Http) {}\r\n  search(term: string): Observable&lt;Hero&#x5B;]&gt; {\r\n    return this.http\r\n               .get(`app\/heroes\/?name=${term}`)\r\n               .map(response =&gt; response.json().data as Hero&#x5B;]);\r\n  }\r\n}<\/pre>\n<p>HeroSearchService\u306ehttp.get\uff08\uff09\u547c\u3073\u51fa\u3057\u306fHeroService\u306ehttp.get\uff08\uff09\u547c\u3073\u51fa\u3057\u3068\u4f3c\u3066\u3044\u307e\u3059\u304c\u3001URL\u306b\u306f\u73fe\u5728\u30af\u30a8\u30ea\u6587\u5b57\u5217\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u3082\u3063\u3068\u91cd\u8981\u306a\u3053\u3068\u306b\u3001\u3042\u306a\u305f\u306f\u3082\u306f\u3084toPromise\uff08\uff09\u3092\u547c\u3073\u51fa\u3059\u3053\u3068\u306f\u3042\u308a\u307e\u305b\u3093\u3002<\/p>\n<p>\u4ee3\u308f\u308a\u306b\u3001Observable\u3092htttp.get\uff08\uff09\u304b\u3089\u5225\u306eRxJS\u6f14\u7b97\u5b50\u3001map\uff08\uff09\u306b\u30c1\u30a7\u30fc\u30f3\u3057\u3066\u8fd4\u4fe1\u3057\u3066\u3001\u30ec\u30b9\u30dd\u30f3\u30b9\u30c7\u30fc\u30bf\u304b\u3089\u30d2\u30fc\u30ed\u30fc\u3092\u62bd\u51fa\u3057\u307e\u3059\u3002<\/p>\n<p>RxJS\u6f14\u7b97\u5b50\u9023\u9396\u306f\u3001\u5fdc\u7b54\u51e6\u7406\u3092\u7c21\u5358\u304b\u3064\u8aad\u307f\u3084\u3059\u304f\u3057\u307e\u3059\u3002\u30aa\u30da\u30ec\u30fc\u30bf\u306b\u3064\u3044\u3066\u306e<a href=\"https:\/\/angular.io\/docs\/ts\/latest\/tutorial\/toh-pt6.html#rxjs-imports\" target=\"_blank\">\u4ee5\u4e0b\u306e\u8aac\u660e<\/a>\u3092\u53c2\u7167\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<h5>HeroSearchComponent<\/h5>\n<p>\u65b0\u3057\u3044HeroSearchService\u3092\u547c\u3073\u51fa\u3059HeroSearchComponent\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<p>\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u306f\u30b7\u30f3\u30d7\u30eb\u3067\u3001\u30c6\u30ad\u30b9\u30c8\u30dc\u30c3\u30af\u30b9\u3068\u4e00\u81f4\u3059\u308b\u691c\u7d22\u7d50\u679c\u306e\u30ea\u30b9\u30c8\u3067\u3059\u3002<\/p>\n<p><strong>src\/app\/hero-search.component.html<\/strong><\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">&lt;div id=&quot;search-component&quot;&gt;\r\n  &lt;h4&gt;Hero Search&lt;\/h4&gt;\r\n  &lt;input #searchBox id=&quot;search-box&quot; (keyup)=&quot;search(searchBox.value)&quot; \/&gt;\r\n  &lt;div&gt;\r\n    &lt;div *ngFor=&quot;let hero of heroes | async&quot;\r\n         (click)=&quot;gotoDetail(hero)&quot; class=&quot;search-result&quot; &gt;\r\n      {{hero.name}}\r\n    &lt;\/div&gt;\r\n  &lt;\/div&gt;\r\n&lt;\/div&gt;<\/pre>\n<p>\u307e\u305f\u3001\u65b0\u3057\u3044\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306e\u30b9\u30bf\u30a4\u30eb\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n<p><strong>src\/app\/hero-search.component.css<\/strong><\/p>\n<pre class=\"brush: css; title: ; notranslate\" title=\"\">.search-result{\r\n  border-bottom: 1px solid gray;\r\n  border-left: 1px solid gray;\r\n  border-right: 1px solid gray;\r\n  width:195px;\r\n  height: 16px;\r\n  padding: 5px;\r\n  background-color: white;\r\n  cursor: pointer;\r\n}\r\n.search-result:hover {\r\n  color: #eee;\r\n  background-color: #607D8B;\r\n}\r\n#search-box{\r\n  width: 200px;\r\n  height: 20px;\r\n}<\/pre>\n<p>\u30e6\u30fc\u30b6\u30fc\u304c\u691c\u7d22\u30dc\u30c3\u30af\u30b9\u306b\u5165\u529b\u3059\u308b\u3068\u3001keyup\u30a4\u30d9\u30f3\u30c8\u30d0\u30a4\u30f3\u30c7\u30a3\u30f3\u30b0\u306b\u3088\u3063\u3066\u3001\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306esearch\uff08\uff09\u30e1\u30bd\u30c3\u30c9\u304c\u65b0\u3057\u3044\u691c\u7d22\u30dc\u30c3\u30af\u30b9\u306e\u5024\u3067\u547c\u3073\u51fa\u3055\u308c\u307e\u3059\u3002<\/p>\n<p>\u4e88\u60f3\u3069\u304a\u308a\u3001*ngFor\u306f\u3001\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306e\u30d2\u30fc\u30ed\u30fc\u30d7\u30ed\u30d1\u30c6\u30a3\u304b\u3089\u30d2\u30fc\u30ed\u30fc\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u7e70\u308a\u8fd4\u3057\u307e\u3059\u3002<\/p>\n<p>\u3057\u304b\u3057\u3001\u3042\u306a\u305f\u304c\u3059\u3050\u306b\u898b\u308b\u3088\u3046\u306b\u3001\u82f1\u96c4\u306e\u30d7\u30ed\u30d1\u30c6\u30a3\u306f\u3001\u82f1\u96c4\u306e\u914d\u5217\u3067\u306f\u306a\u304f\u3001\u82f1\u96c4\u306e\u914d\u5217\u306e\u30aa\u30d6\u30b6\u30fc\u30d0\u30d6\u30eb\u3067\u3059\u3002 <\/p>\n<p>*ngFor\u306f\u3001\u975e\u540c\u671f\u30d1\u30a4\u30d7\uff08AsyncPipe\uff09\u3092\u7d4c\u7531\u3059\u308b\u307e\u3067Observable\u3067\u4f55\u3082\u3067\u304d\u307e\u305b\u3093\u3002<\/p>\n<p>\u975e\u540c\u671f\u30d1\u30a4\u30d7\u306fObservable\u306b\u30b5\u30d6\u30b9\u30af\u30e9\u30a4\u30d6\u3057\u3001*ngFor\u306e\u30d2\u30fc\u30ed\u30fc\u306e\u914d\u5217\u3092\u751f\u6210\u3057\u307e\u3059\u3002<\/p>\n<p>HeroSearchComponent\u30af\u30e9\u30b9\u3068\u30e1\u30bf\u30c7\u30fc\u30bf\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<p><strong>src\/app\/hero-search.component.ts<\/strong><\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">import { Component, OnInit } from '@angular\/core';\r\nimport { Router }            from '@angular\/router';\r\nimport { Observable }        from 'rxjs\/Observable';\r\nimport { Subject }           from 'rxjs\/Subject';\r\n\/\/ Observable class extensions\r\nimport 'rxjs\/add\/observable\/of';\r\n\/\/ Observable operators\r\nimport 'rxjs\/add\/operator\/catch';\r\nimport 'rxjs\/add\/operator\/debounceTime';\r\nimport 'rxjs\/add\/operator\/distinctUntilChanged';\r\nimport { HeroSearchService } from '.\/hero-search.service';\r\nimport { Hero } from '.\/hero';\r\n@Component({\r\n  selector: 'hero-search',\r\n  templateUrl: '.\/hero-search.component.html',\r\n  styleUrls: &#x5B; '.\/hero-search.component.css' ],\r\n  providers: &#x5B;HeroSearchService]\r\n})\r\nexport class HeroSearchComponent implements OnInit {\r\n  heroes: Observable&lt;Hero&#x5B;]&gt;;\r\n  private searchTerms = new Subject&lt;string&gt;();\r\n  constructor(\r\n    private heroSearchService: HeroSearchService,\r\n    private router: Router) {}\r\n  \/\/ Push a search term into the observable stream.\r\n  search(term: string): void {\r\n    this.searchTerms.next(term);\r\n  }\r\n  ngOnInit(): void {\r\n    this.heroes = this.searchTerms\r\n      .debounceTime(300)        \/\/ wait 300ms after each keystroke before considering the term\r\n      .distinctUntilChanged()   \/\/ ignore if next search term is same as previous\r\n      .switchMap(term =&gt; term   \/\/ switch to new observable each time the term changes\r\n        \/\/ return the http search observable\r\n        ? this.heroSearchService.search(term)\r\n        \/\/ or the observable of empty heroes if there was no search term\r\n        : Observable.of&lt;Hero&#x5B;]&gt;(&#x5B;]))\r\n      .catch(error =&gt; {\r\n        \/\/ TODO: add real error handling\r\n        console.log(error);\r\n        return Observable.of&lt;Hero&#x5B;]&gt;(&#x5B;]);\r\n      });\r\n  }\r\n  gotoDetail(hero: Hero): void {\r\n    let link = &#x5B;'\/detail', hero.id];\r\n    this.router.navigate(link);\r\n  }\r\n}<\/pre>\n<h5>SEARCH TERMS<\/h5>\n<p>searchTerms\u306b\u7126\u70b9\u3092\u5f53\u3066\u308b\uff1a<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">private searchTerms = new Subject&lt;string&gt;();\r\n\r\n\/\/ Push a search term into the observable stream.\r\nsearch(term: string): void {\r\n  this.searchTerms.next(term);\r\n}<\/pre>\n<p>\u30b5\u30d6\u30b8\u30a7\u30af\u30c8\u306f\u3001\u89b3\u6e2c\u53ef\u80fd\u306a\u30a4\u30d9\u30f3\u30c8\u30b9\u30c8\u30ea\u30fc\u30e0\u306e\u30d7\u30ed\u30c7\u30e5\u30fc\u30b5\u3067\u3059\u3002 searchTerms\u306f\u3001\u540d\u524d\u306e\u691c\u7d22\u306e\u30d5\u30a3\u30eb\u30bf\u6761\u4ef6\u3067\u3042\u308bObservable of strings\u3092\u751f\u6210\u3057\u307e\u3059\u3002<\/p>\n<p>search\uff08\uff09\u3092\u547c\u3073\u51fa\u3059\u305f\u3073\u306b\u3001next\uff08\uff09\u3092\u547c\u3073\u51fa\u3059\u3053\u3068\u306b\u3088\u3063\u3066\u3001\u3053\u306e\u6587\u5b57\u5217\u306e\u89b3\u6e2c\u53ef\u80fd\u306a\u30b9\u30c8\u30ea\u30fc\u30e0\u306b\u65b0\u3057\u3044\u6587\u5b57\u5217\u304c\u8ffd\u52a0\u3055\u308c\u307e\u3059\u3002<\/p>\n<h5>INITIALIZE THE HEROES PROPERTY (NGONINIT)<\/h5>\n<p>\u88ab\u9a13\u8005\u306f\u307e\u305f\u89b3\u5bdf\u53ef\u80fd\u3067\u3042\u308b\u3002\u691c\u7d22\u7528\u8a9e\u306e\u30b9\u30c8\u30ea\u30fc\u30e0\u3092Hero\u914d\u5217\u306e\u30b9\u30c8\u30ea\u30fc\u30e0\u306b\u5909\u63db\u3057\u3001\u305d\u306e\u7d50\u679c\u3092heroes\u30d7\u30ed\u30d1\u30c6\u30a3\u306b\u5272\u308a\u5f53\u3066\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">heroes: Observable&lt;Hero&#x5B;]&gt;;\r\n\r\nngOnInit(): void {\r\n  this.heroes = this.searchTerms\r\n    .debounceTime(300)        \/\/ wait 300ms after each keystroke before considering the term\r\n    .distinctUntilChanged()   \/\/ ignore if next search term is same as previous\r\n    .switchMap(term =&gt; term   \/\/ switch to new observable each time the term changes\r\n      \/\/ return the http search observable\r\n      ? this.heroSearchService.search(term)\r\n      \/\/ or the observable of empty heroes if there was no search term\r\n      : Observable.of&lt;Hero&#x5B;]&gt;(&#x5B;]))\r\n    .catch(error =&gt; {\r\n      \/\/ TODO: add real error handling\r\n      console.log(error);\r\n      return Observable.of&lt;Hero&#x5B;]&gt;(&#x5B;]);\r\n    });\r\n}<\/pre>\n<p>\u3059\u3079\u3066\u306e\u30e6\u30fc\u30b6\u30fc\u306e\u30ad\u30fc\u30b9\u30c8\u30ed\u30fc\u30af\u3092\u76f4\u63a5HeroSearchService\u306b\u6e21\u3059\u3068\u3001\u904e\u5ea6\u306e\u91cf\u306eHTTP\u8981\u6c42\u304c\u4f5c\u6210\u3055\u308c\u3001\u30b5\u30fc\u30d0\u30fc\u30ea\u30bd\u30fc\u30b9\u306b\u8ab2\u91d1\u3055\u308c\u3001\u30bb\u30eb\u30e9\u30fc\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u306e\u30c7\u30fc\u30bf\u30d7\u30e9\u30f3\u3092\u4ecb\u3057\u3066\u713c\u304d\u4ed8\u3051\u3089\u308c\u307e\u3059\u3002<\/p>\n<p>\u4ee3\u308f\u308a\u306b\u3001Observable\u6f14\u7b97\u5b50\u3092\u9023\u9396\u3055\u305b\u3066\u3001Observable\u3068\u3044\u3046\u6587\u5b57\u5217\u3078\u306e\u8981\u6c42\u306e\u6d41\u308c\u3092\u6e1b\u3089\u3059\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002 <\/p>\n<p>HeroSearchService\u3078\u306e\u547c\u3073\u51fa\u3057\u56de\u6570\u3092\u6e1b\u3089\u3057\u3066\u3082\u3001\u30bf\u30a4\u30e0\u30ea\u30fc\u306a\u7d50\u679c\u304c\u5f97\u3089\u308c\u307e\u3059\u3002\u65b9\u6cd5\u306f\u6b21\u306e\u3068\u304a\u308a\u3067\u3059\u3002<\/p>\n<p>debounceTime\uff08300\uff09\u306f\u3001\u6700\u65b0\u306e\u6587\u5b57\u5217\u3092\u6e21\u3059\u524d\u306b\u3001\u65b0\u3057\u3044\u6587\u5b57\u5217\u30a4\u30d9\u30f3\u30c8\u306e\u30d5\u30ed\u30fc\u304c300\u30df\u30ea\u79d2\u9593\u505c\u6b62\u3059\u308b\u307e\u3067\u5f85\u6a5f\u3057\u307e\u3059\u3002 300\u30df\u30ea\u79d2\u4ee5\u4e0a\u306e\u983b\u5ea6\u3067\u30ea\u30af\u30a8\u30b9\u30c8\u3092\u884c\u3046\u3053\u3068\u306f\u3042\u308a\u307e\u305b\u3093\u3002<\/p>\n<p>\u30fb distinctUntilChanged\u306f\u3001\u30d5\u30a3\u30eb\u30bf\u30fc\u30fb\u30c6\u30ad\u30b9\u30c8\u304c\u5909\u66f4\u3055\u308c\u305f\u5834\u5408\u306b\u306e\u307f\u8981\u6c42\u304c\u9001\u4fe1\u3055\u308c\u308b\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n<p>\u30fb switchMap\uff08\uff09\u306f\u3001debounce\u304a\u3088\u3073distinctUntilChanged\u3092\u4f7f\u7528\u3057\u3066\u691c\u7d22\u3059\u308b\u5404\u691c\u7d22\u30bf\u30fc\u30e0\u306e\u691c\u7d22\u30b5\u30fc\u30d3\u30b9\u3092\u547c\u3073\u51fa\u3057\u307e\u3059\u3002<\/p>\n<p>\u30fb \u3053\u308c\u306f\u3001\u4ee5\u524d\u306e\u691c\u7d22\u30aa\u30d6\u30b6\u30fc\u30d0\u30d6\u30eb\u3092\u30ad\u30e3\u30f3\u30bb\u30eb\u3057\u3066\u7834\u68c4\u3057\u3001\u89b3\u5bdf\u53ef\u80fd\u306a\u6700\u65b0\u306e\u691c\u7d22\u30b5\u30fc\u30d3\u30b9\u306e\u307f\u3092\u8fd4\u3057\u307e\u3059\u3002<\/p>\n<p>&#8220;&#8220;&#8220;<br \/>\n<a href=\"http:\/\/www.learnrxjs.io\/operators\/transformation\/switchmap.html\" target=\"_blank\">switchMap operator<\/a> \uff08\u4ee5\u524d\u306fflatMapLatest\uff09\u3092\u4f7f\u7528\u3057\u3066\u3001\u3059\u3079\u3066\u306e\u4fee\u98fe\u30ad\u30fc\u30a4\u30d9\u30f3\u30c8\u304chttp\uff08\uff09\u30e1\u30bd\u30c3\u30c9\u547c\u3073\u51fa\u3057\u3092\u30c8\u30ea\u30ac\u30fc\u3067\u304d\u307e\u3059\u3002\u30ea\u30af\u30a8\u30b9\u30c8\u9593\u306b300ms\u306e\u4f11\u6b62\u6642\u9593\u304c\u3042\u3063\u3066\u3082\u3001\u98db\u884c\u4e2d\u306b\u8907\u6570\u306eHTTP\u30ea\u30af\u30a8\u30b9\u30c8\u3092\u6301\u3064\u3053\u3068\u304c\u3067\u304d\u3001\u9001\u4fe1\u3055\u308c\u305f\u9806\u5e8f\u3067\u8fd4\u3055\u308c\u306a\u3044\u3053\u3068\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>switchMap\uff08\uff09\u306f\u3001\u6700\u65b0\u306ehttp\u30e1\u30bd\u30c3\u30c9\u547c\u3073\u51fa\u3057\u304b\u3089\u306e\u30aa\u30d6\u30b6\u30fc\u30d0\u30d6\u30eb\u306e\u307f\u3092\u8fd4\u3057\u306a\u304c\u3089\u3001\u5143\u306e\u30ea\u30af\u30a8\u30b9\u30c8\u306e\u9806\u5e8f\u3092\u4fdd\u6301\u3057\u307e\u3059\u3002\u4ee5\u524d\u306e\u30b3\u30fc\u30eb\u306e\u7d50\u679c\u306f\u30ad\u30e3\u30f3\u30bb\u30eb\u3055\u308c\u3001\u7834\u68c4\u3055\u308c\u307e\u3059\u3002<\/p>\n<p>\u691c\u7d22\u30c6\u30ad\u30b9\u30c8\u304c\u7a7a\u306e\u5834\u5408\u3001http\uff08\uff09\u30e1\u30bd\u30c3\u30c9\u547c\u3073\u51fa\u3057\u3082\u77ed\u7d61\u3055\u308c\u3001\u7a7a\u306e\u914d\u5217\u3092\u542b\u3080observable\u304c\u8fd4\u3055\u308c\u307e\u3059\u3002<\/p>\n<p>\u30b5\u30fc\u30d3\u30b9\u304c\u305d\u306e\u6a5f\u80fd\u3092\u30b5\u30dd\u30fc\u30c8\u3059\u308b\u307e\u3067\u3001HeroSearchService Observable\u3092\u30ad\u30e3\u30f3\u30bb\u30eb\u3057\u3066\u3082\u4fdd\u7559\u4e2d\u306eHTTP\u8981\u6c42\u306f\u5b9f\u969b\u306b\u306f\u4e2d\u6b62\u3055\u308c\u307e\u305b\u3093\u3002\u4eca\u306e\u3068\u3053\u308d\u3001\u671b\u307e\u3057\u304f\u306a\u3044\u7d50\u679c\u306f\u7834\u68c4\u3055\u308c\u307e\u3059\u3002<br \/>\n&#8220;&#8220;&#8220;<\/p>\n<p>\u30fb catch\u306f\u5931\u6557\u3057\u305fobservable\u3092\u508d\u53d7\u3057\u307e\u3059\u3002\u7c21\u5358\u306a\u4f8b\u3067\u306f\u3001\u30a8\u30e9\u30fc\u3092\u30b3\u30f3\u30bd\u30fc\u30eb\u306b\u51fa\u529b\u3057\u307e\u3059\u3002\u6b21\u306b\u3001\u691c\u7d22\u7d50\u679c\u3092\u30af\u30ea\u30a2\u3059\u308b\u306b\u306f\u3001\u7a7a\u306e\u914d\u5217\u3092\u542b\u3080observable\u3092\u8fd4\u3057\u307e\u3059\u3002<\/p>\n<h5>Import RxJS operators<\/h5>\n<p>\u307b\u3068\u3093\u3069\u306eRxJS\u6f14\u7b97\u5b50\u306f\u3001Angular\u306eObservable\u30d9\u30fc\u30b9\u306e\u5b9f\u88c5\u306b\u306f\u542b\u307e\u308c\u3066\u3044\u307e\u305b\u3093\u3002\u57fa\u672c\u5b9f\u88c5\u306b\u306f\u3001Angular\u81ea\u4f53\u306b\u5fc5\u8981\u306a\u3082\u306e\u3060\u3051\u304c\u542b\u307e\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u3088\u308a\u591a\u304f\u306eRxJS\u6a5f\u80fd\u304c\u5fc5\u8981\u306a\u5834\u5408\u306f\u3001\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u308b\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u30a4\u30f3\u30dd\u30fc\u30c8\u3057\u3066Observable\u3092\u62e1\u5f35\u3057\u307e\u3059\u3002\u3053\u306e\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306b\u5fc5\u8981\u306a\u3059\u3079\u3066\u306eRxJS\u30a4\u30f3\u30dd\u30fc\u30c8\u306f\u6b21\u306e\u3068\u304a\u308a\u3067\u3059\u3002<\/p>\n<p><strong>src\/app\/hero-search.component.ts (rxjs imports)<\/strong><\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">import { Observable }        from 'rxjs\/Observable';\r\nimport { Subject }           from 'rxjs\/Subject';\r\n\r\n\/\/ Observable class extensions\r\nimport 'rxjs\/add\/observable\/of';\r\n\r\n\/\/ Observable operators\r\nimport 'rxjs\/add\/operator\/catch';\r\nimport 'rxjs\/add\/operator\/debounceTime';\r\nimport 'rxjs\/add\/operator\/distinctUntilChanged';<\/pre>\n<p>\u30a4\u30f3\u30dd\u30fc\u30c8\u306e &#8216;rxjs \/ add \/ &#8230;&#8217;\u69cb\u6587\u306f\u3088\u304f\u77e5\u3089\u308c\u3066\u3044\u306a\u3044\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002 {{}}\u4e2d\u62ec\u5f27\u306e\u9593\u306b\u3042\u308b\u30b7\u30f3\u30dc\u30eb\u306e\u901a\u5e38\u306e\u30ea\u30b9\u30c8\u306f\u3042\u308a\u307e\u305b\u3093\u3002<\/p>\n<p>\u6f14\u7b97\u5b50\u30b7\u30f3\u30dc\u30eb\u81ea\u4f53\u306f\u5fc5\u8981\u3042\u308a\u307e\u305b\u3093\u3002\u3044\u305a\u308c\u306e\u5834\u5408\u3082\u3001\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u30a4\u30f3\u30dd\u30fc\u30c8\u3059\u308b\u5358\u306a\u308b\u884c\u70ba\u306f\u3001\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u30b9\u30af\u30ea\u30d7\u30c8\u30d5\u30a1\u30a4\u30eb\u3092\u30ed\u30fc\u30c9\u3057\u3066\u5b9f\u884c\u3057\u3001\u30aa\u30d6\u30b6\u30fc\u30d0\u30d6\u30eb\u30af\u30e9\u30b9\u306b\u6f14\u7b97\u5b50\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n<h5>Add the search component to the dashboard<\/h5>\n<p>\u30d2\u30fc\u30ed\u30fc\u691c\u7d22\u306eHTML\u8981\u7d20\u3092DashboardComponent\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u306e\u4e0b\u90e8\u306b\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n<p><strong>src\/app\/dashboard.component.html<\/strong><\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">&lt;h3&gt;Top Heroes&lt;\/h3&gt;\r\n&lt;div class=&quot;grid grid-pad&quot;&gt;\r\n  &lt;a *ngFor=&quot;let hero of heroes&quot;  &#x5B;routerLink]=&quot;&#x5B;'\/detail', hero.id]&quot;  class=&quot;col-1-4&quot;&gt;\r\n    &lt;div class=&quot;module hero&quot;&gt;\r\n      &lt;h4&gt;{{hero.name}}&lt;\/h4&gt;\r\n    &lt;\/div&gt;\r\n  &lt;\/a&gt;\r\n&lt;\/div&gt;\r\n&lt;hero-search&gt;&lt;\/hero-search&gt;<\/pre>\n<p>\u6700\u5f8c\u306b\u3001heroSearchComponent\u3092hero-search.component.ts\u304b\u3089\u30a4\u30f3\u30dd\u30fc\u30c8\u3057\u3001\u305d\u308c\u3092\u5ba3\u8a00\u914d\u5217\u306b\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n<p><strong>src\/app\/app.module.ts (search)<\/strong><\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">  declarations: &#x5B;\r\n    AppComponent,\r\n    DashboardComponent,\r\n    HeroDetailComponent,\r\n    HeroesComponent,\r\n    HeroSearchComponent\r\n  ],<\/pre>\n<p>\u30a2\u30d7\u30ea\u3092\u3082\u3046\u4e00\u5ea6\u5b9f\u884c\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u30c0\u30c3\u30b7\u30e5\u30dc\u30fc\u30c9\u3067\u3001\u691c\u7d22\u30dc\u30c3\u30af\u30b9\u306b\u30c6\u30ad\u30b9\u30c8\u3092\u5165\u529b\u3057\u307e\u3059\u3002\u65e2\u5b58\u306e\u30d2\u30fc\u30ed\u30fc\u540d\u3068\u4e00\u81f4\u3059\u308b\u6587\u5b57\u3092\u5165\u529b\u3059\u308b\u3068\u3001\u6b21\u306e\u3088\u3046\u306b\u8868\u793a\u3055\u308c\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/2017\/04\/toh-hero-search.png\" alt=\"\" width=\"240\" height=\"224\" class=\"alignnone size-full wp-image-7792\" \/><\/p>\n<h4>App structure and code<\/h4>\n<p>\u3053\u306e\u30da\u30fc\u30b8\u306e <a href=\"https:\/\/angular.io\/resources\/live-examples\/toh-6\/ts\/eplnkr.html\" target=\"_blank\">live example<\/a> \/ <a href=\"https:\/\/angular.io\/resources\/zips\/toh-6\/toh-6.zip\" target=\"_blank\">downloadable example<\/a> \u306e\u30b5\u30f3\u30d7\u30eb\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u3092\u78ba\u8a8d\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u6b21\u306e\u69cb\u9020\u3092\u6301\u3063\u3066\u3044\u308b\u3053\u3068\u3092\u78ba\u8a8d\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">angular-tour-of-heroes\r\n\u251c\u2500\u2500src\r\n\u2502 \u251c\u2500\u2500app\r\n\u2502 \u2502  \u251c\u2500\u2500app.component.ts\r\n\u2502 \u2502  \u251c\u2500\u2500app.component.css\r\n\u2502 \u2502  \u251c\u2500\u2500app.module.ts\r\n\u2502 \u2502  \u251c\u2500\u2500app-routing.module.ts\r\n\u2502 \u2502  \u251c\u2500\u2500dashboard.component.css\r\n\u2502 \u2502  \u251c\u2500\u2500dashboard.component.html\r\n\u2502 \u2502  \u251c\u2500\u2500dashboard.component.ts\r\n\u2502 \u2502  \u251c\u2500\u2500hero.service.ts\r\n\u2502 \u2502  \u251c\u2500\u2500hero.ts\r\n\u2502 \u2502  \u251c\u2500\u2500hero-detail.component.css\r\n\u2502 \u2502  \u251c\u2500\u2500hero-detail.component.html\r\n\u2502 \u2502  \u251c\u2500\u2500hero-detail.component.ts\r\n\u2502 \u2502  \u251c\u2500\u2500hero-search.component.html (new)\r\n\u2502 \u2502  \u251c\u2500\u2500hero-search.component.css (new)\r\n\u2502 \u2502  \u251c\u2500\u2500hero-search.component.ts (new)\r\n\u2502 \u2502  \u251c\u2500\u2500hero-search.service.ts (new)\r\n\u2502 \u2502  \u251c\u2500\u2500hero.service.ts\r\n\u2502 \u2502  \u251c\u2500\u2500heroes.component.css\r\n\u2502 \u2502  \u251c\u2500\u2500heroes.component.html\r\n\u2502 \u2502  \u251c\u2500\u2500heroes.component.ts\r\n\u2502 \u2502  \u2514\u2500\u2500in-memory-data.service.ts (new)\r\n\u2502 \u251c\u2500\u2500main.ts\r\n\u2502 \u251c\u2500\u2500index.html\r\n\u2502 \u251c\u2500\u2500styles.css\r\n\u2502 \u251c\u2500\u2500systemjs.config.js\r\n\u2502 \u2514\u2500\u2500tsconfig.json\r\n\u251c\u2500\u2500node_modules ...\r\n\u2514\u2500\u2500package.json<\/pre>\n<h4>Home Stretch<\/h4>\n<p>\u3042\u306a\u305f\u306f\u3042\u306a\u305f\u306e\u65c5\u306e\u7d42\u308f\u308a\u306b\u304a\u308a\u3001\u3042\u306a\u305f\u306f\u591a\u304f\u3092\u6210\u3057\u9042\u3052\u307e\u3057\u305f\u3002<\/p>\n<p>\u30fb \u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3067HTTP\u3092\u4f7f\u7528\u3059\u308b\u305f\u3081\u306b\u5fc5\u8981\u306a\u4f9d\u5b58\u95a2\u4fc2\u3092\u8ffd\u52a0\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u30fb \u3042\u306a\u305f\u306fHeroService\u3092\u30ea\u30d5\u30a1\u30af\u30bf\u30ea\u30f3\u30b0\u3057\u3066\u3001Web API\u304b\u3089\u30d2\u30fc\u30ed\u30fc\u3092\u30ed\u30fc\u30c9\u3057\u307e\u3059\u3002<\/p>\n<p>\u30fb post\uff08\uff09\u3001put\uff08\uff09\u3001\u304a\u3088\u3073delete\uff08\uff09\u30e1\u30bd\u30c3\u30c9\u3092\u30b5\u30dd\u30fc\u30c8\u3059\u308b\u3088\u3046\u306bHeroService\u3092\u62e1\u5f35\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u30fb \u30d2\u30fc\u30ed\u30fc\u306e\u8ffd\u52a0\u3001\u7de8\u96c6\u3001\u524a\u9664\u3092\u53ef\u80fd\u306b\u3059\u308b\u3088\u3046\u306b\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3092\u66f4\u65b0\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u30fb \u30a4\u30f3\u30e1\u30e2\u30eaWeb API\u3092\u8a2d\u5b9a\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u30fb Observables\u306e\u4f7f\u3044\u65b9\u3092\u5b66\u3073\u307e\u3057\u305f\u3002<\/p>\n<p>\u3053\u306e\u30da\u30fc\u30b8\u3067\u8ffd\u52a0\u307e\u305f\u306f\u5909\u66f4\u3057\u305f\u30d5\u30a1\u30a4\u30eb\u306f\u6b21\u306e\u3068\u304a\u308a\u3067\u3059\u3002<\/p>\n<p><a href=\"https:\/\/angular.io\/docs\/ts\/latest\/tutorial\/toh-pt6.html#!#home-stretch\" target=\"_blank\">\u516c\u5f0f\u30da\u30fc\u30b8\u53c2\u7167<\/a><\/p>\n<h4>Next step<\/h4>\n<p>\u3053\u306e\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u3067\u898b\u3064\u304b\u3063\u305f\u6982\u5ff5\u3068\u30d7\u30e9\u30af\u30c6\u30a3\u30b9\u306e\u8a73\u7d30\u3092\u8aad\u3080\u3053\u3068\u304c\u3067\u304d\u308b <a href=\"https:\/\/angular.io\/docs\/ts\/latest\/guide\/learning-angular.html#architecture\" target=\"_blank\">learning path<\/a>\u306b\u623b\u308a\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>HTTP GETTING AND SAVING DATA \u3053\u3061\u3089\u306e\u30da\u30fc\u30b8\u306f\u3001\u4ee5\u4e0b\u306e\u30da\u30fc\u30b8\u306e\u7c21\u5358\u306a\u548c\u8a33\u3067\u3059\u3002 Angular2 tutorial | HTTP \u524d\u56de Angular2\u306e\u59cb\u3081\u65b9\u3002Angular2 \u516c\u5f0f\u30c1\u30e5\u30fc\u30c8 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[203],"tags":[176,166,37,47,46,44,45,111,39,178,138,78,114,118],"class_list":{"0":"post-7523","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"hentry","6":"category-angular2","7":"tag-html5","8":"tag-iphone","9":"tag-iphone-","10":"tag-javascript-2","11":"tag-js","12":"tag-web","14":"tag-wordpress-2","15":"tag-39","16":"tag-178","17":"tag-138","18":"tag-78","19":"tag-114","20":"tag-118"},"_links":{"self":[{"href":"https:\/\/www.webcyou.com\/index.php?rest_route=\/wp\/v2\/posts\/7523","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.webcyou.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webcyou.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webcyou.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webcyou.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7523"}],"version-history":[{"count":8,"href":"https:\/\/www.webcyou.com\/index.php?rest_route=\/wp\/v2\/posts\/7523\/revisions"}],"predecessor-version":[{"id":7797,"href":"https:\/\/www.webcyou.com\/index.php?rest_route=\/wp\/v2\/posts\/7523\/revisions\/7797"}],"wp:attachment":[{"href":"https:\/\/www.webcyou.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7523"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webcyou.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7523"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webcyou.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7523"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}