{"id":7512,"date":"2017-01-20T04:18:56","date_gmt":"2017-01-19T19:18:56","guid":{"rendered":"http:\/\/www.webcyou.com\/?p=7512"},"modified":"2020-03-20T17:56:40","modified_gmt":"2020-03-20T08:56:40","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-masterdetail%ef%bc%88%e7%b0%a1%e5%8d%98%e3%81%aa","status":"publish","type":"post","link":"https:\/\/www.webcyou.com\/?p=7512","title":{"rendered":"Angular2\u306e\u59cb\u3081\u65b9\u3002Angular2 \u516c\u5f0f\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb &#8211; Master\/Detail\uff08\u7c21\u5358\u306a\u548c\u8a33\uff09"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7584\" src=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/angular_md-1.png\" alt=\"angular_md\" width=\"600\" height=\"300\" srcset=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/angular_md-1.png 600w, https:\/\/www.webcyou.com\/wp-content\/uploads\/angular_md-1-300x150.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/p>\n<p>MASTER\/DETAIL<\/p>\n<p>\u3053\u3061\u3089\u306e\u30da\u30fc\u30b8\u306f\u3001\u3053\u3061\u3089\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-pt2.html\">Angular2 tutorial | MASTER\/DETAIL<\/a><\/p>\n<p>\u305d\u306e\u4ed6<\/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 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>\u79c1\u305f\u3061\u306e\u7269\u8a9e\u306f\u3088\u308a\u591a\u304f\u306e\u82f1\u96c4\u3092\u5fc5\u8981\u3068\u3057\u307e\u3059\u3002<\/p>\n<p>\u30d2\u30fc\u30ed\u30fc\u306e\u30a2\u30d7\u30ea\u3092\u62e1\u5f35\u3057\u3066\u30d2\u30fc\u30ed\u30fc\u306e\u30ea\u30b9\u30c8\u3092\u8868\u793a\u3057\u3001\u30e6\u30fc\u30b6\u30fc\u304c\u30d2\u30fc\u30ed\u30fc\u3092\u9078\u629e\u3067\u304d\u308b\u3088\u3046\u306b\u3057\u3001\u30d2\u30fc\u30ed\u30fc\u306e\u8a73\u7d30\u3092\u8868\u793a\u3057\u307e\u3059\u3002<\/p>\n<p>\u3053\u306e\u30d1\u30fc\u30c4\u306e\u30e9\u30a4\u30d6\u30b5\u30f3\u30d7\u30eb\u3092\u5b9f\u884c\u3057\u307e\u3059\u3002<\/p>\n<p>\u30d2\u30fc\u30ed\u30fc\u306e\u30ea\u30b9\u30c8\u3092\u8868\u793a\u3059\u308b\u305f\u3081\u306b\u5fc5\u8981\u306a\u3082\u306e\u3092\u7528\u610f\u3057\u307e\u3057\u3087\u3046\u3002\u307e\u305a\u3001\u30d2\u30fc\u30ed\u30fc\u306e\u30ea\u30b9\u30c8\u304c\u5fc5\u8981\u3067\u3059\u3002<\/p>\n<p>\u305d\u308c\u3089\u306e\u30d2\u30fc\u30ed\u30fc\u3092\u30d3\u30e5\u30fc\u306e\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u306b\u8868\u793a\u3057\u305f\u3044\u306e\u3067\u3001\u305d\u306e\u30d2\u30fc\u30ed\u30fc\u3092\u884c\u3046\u65b9\u6cd5\u304c\u5fc5\u8981\u3067\u3059\u3002<\/p>\n<p>Run the\u00a0<a href=\"https:\/\/angular.io\/resources\/live-examples\/toh-2\/ts\/eplnkr.html\" target=\"_blank\" rel=\"noopener\">live example<\/a><\/p>\n<h4>Where We Left Off<\/h4>\n<p>\u30d2\u30fc\u30ed\u30fc\u30c4\u30a2\u30fc\u306e\u30d1\u30fc\u30c82\u3092\u7d9a\u884c\u3059\u308b\u524d\u306b\u3001\u30d1\u30fc\u30c81\u306e\u5f8c\u306b\u6b21\u306e\u69cb\u9020\u3092\u6301\u3063\u3066\u3044\u308b\u3053\u3068\u3092\u78ba\u8a8d\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u305d\u3046\u3067\u306a\u3044\u5834\u5408\u306f\u3001\u30d1\u30fc\u30c81\u306b\u623b\u3063\u3066\u3001\u9003\u3057\u305f\u3082\u306e\u3092\u898b\u3064\u3051\u51fa\u3059\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">angular-tour-of-heroes\r\n\u251c\u2500\u2500 app\r\n\u2502 \u251c\u2500\u2500 app.component.ts\r\n\u2502 \u251c\u2500\u2500 app.module.ts\r\n\u2502 \u2514\u2500\u2500 main.ts\r\n\u251c\u2500\u2500 node_modules ...\r\n\u251c\u2500\u2500 index.html\r\n\u251c\u2500\u2500 package.json\r\n\u251c\u2500\u2500 styles.css\r\n\u251c\u2500\u2500 systemjs.config.js\r\n\u2514\u2500\u2500 tsconfig.json<\/pre>\n<h5>Keep the app transpiling and running<\/h5>\n<p>TypeScript\u30b3\u30f3\u30d1\u30a4\u30e9\u3092\u8d77\u52d5\u3057\u3001\u5909\u66f4\u3092\u76e3\u8996\u3057\u3066\u304b\u3089\u30b5\u30fc\u30d0\u30fc\u3092\u8d77\u52d5\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u3053\u308c\u3092\u5165\u529b\u3059\u308b\u306b\u306f<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">npm start<\/pre>\n<p>\u3053\u308c\u306b\u3088\u308a\u3001Tour of Heroes\u3092\u5f15\u304d\u7d9a\u304d\u69cb\u7bc9\u3057\u306a\u304c\u3089\u3001\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u5b9f\u884c\u3057\u7d9a\u3051\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<h4>Displaying Our Heroes<\/h4>\n<h5>Creating heroes<\/h5>\n<p>10\u4eba\u306e\u30d2\u30fc\u30ed\u30fc\u306e\u914d\u5217\u3092\u4f5c\u308a\u307e\u3057\u3087\u3046\u3002<\/p>\n<p><strong>app.component.ts (hero array)<\/strong><\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">const HEROES: Hero&#x5B;] = &#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];<\/pre>\n<h5>Exposing heroes<\/h5>\n<p>AppComponent\u306b\u30d0\u30a4\u30f3\u30c7\u30a3\u30f3\u30b0\u3059\u308b\u3001\u30d2\u30fc\u30ed\u30fc\u306epublic\u30d7\u30ed\u30d1\u30c6\u30a3\u3092\u4f5c\u6210\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<p><strong>app.component.ts (hero array property)<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">heroes = HEROES;<\/pre>\n<p>\u30d2\u30fc\u30ed\u30fc\u306e\u578b\u3092\u5b9a\u7fa9\u3059\u308b\u5fc5\u8981\u306f\u3042\u308a\u307e\u305b\u3093\u3067\u3057\u305f\u3002 TypeScript\u306fHEROES\u914d\u5217\u304b\u3089\u63a8\u8ad6\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>&#8212;<br \/>\n\u3053\u3053\u3067\u306f\u3001\u3053\u306e\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u30af\u30e9\u30b9\u3067\u30d2\u30fc\u30ed\u30fc\u30ea\u30b9\u30c8\u3092\u5b9a\u7fa9\u3067\u304d\u307e\u3057\u305f\u3002<\/p>\n<p>\u3057\u304b\u3057\u3001\u6700\u7d42\u7684\u306b\u6211\u3005\u306f\u30c7\u30fc\u30bf\u30b5\u30fc\u30d3\u30b9\u304b\u3089\u82f1\u96c4\u3092\u5f97\u3088\u3046\u3068\u3057\u3066\u304a\u308a\u307e\u3059\u3002\u306a\u306e\u3067\u3001\u30d2\u30fc\u30ed\u30fc\u30c7\u30fc\u30bf\u3092\u30af\u30e9\u30b9\u306e\u5b9f\u88c5\u304b\u3089\u6700\u521d\u304b\u3089\u5206\u96e2\u3059\u308b\u306e\u304c\u7406\u306b\u304b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<br \/>\n&#8212;<\/p>\n<h5>Displaying heroes in a template<\/h5>\n<p>\u79c1\u305f\u3061\u306e\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306f\u30d2\u30fc\u30ed\u30fc\u3092\u6301\u3063\u3066\u3044\u307e\u3059\u3002\u79c1\u305f\u3061\u306e\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u306b\u30ea\u30b9\u30c8\u3092\u4f5c\u6210\u3057\u3066\u8868\u793a\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002\u30bf\u30a4\u30c8\u30eb\u306e\u4e0b\u306b\u30d2\u30fc\u30ed\u30fc\u306e\u8a73\u7d30\u306e\u4e0a\u306b\u6b21\u306eHTML\u306e\u584a\u3092\u633f\u5165\u3057\u307e\u3059\u3002<\/p>\n<p><strong>app.component.ts (heroes template)<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">&lt;h2&gt;My Heroes&lt;\/h2&gt;\r\n&lt;ul class=&quot;heroes&quot;&gt;\r\n  &lt;li&gt;\r\n    &lt;!-- each hero goes here --&gt;\r\n  &lt;\/li&gt;\r\n&lt;\/ul&gt;<\/pre>\n<p>\u4eca\u3001\u79c1\u305f\u3061\u306f\u30d2\u30fc\u30ed\u30fc\u3067\u6e80\u305f\u3059\u3053\u3068\u306e\u3067\u304d\u308b\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3092\u7528\u610f\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<h5>Listing heroes with ngFor<\/h5>\n<p>\u79c1\u305f\u3061\u306f\u3001\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u5185\u306e\u30d2\u30fc\u30ed\u30fc\u306e\u914d\u5217\u3092\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u306b\u30d0\u30a4\u30f3\u30c9\u3057\u3001\u53cd\u5fa9\u51e6\u7406\u3057\u3066\u500b\u3005\u306b\u8868\u793a\u3057\u305f\u3044\u3068\u8003\u3048\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u3053\u308c\u3092\u884c\u3046\u306b\u306fAngular\u306e\u52a9\u3051\u304c\u5fc5\u8981\u3067\u3059\u3002\u3053\u308c\u3092\u30b9\u30c6\u30c3\u30d7\u3054\u3068\u306b\u884c\u3063\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\u307e\u305a\u3001\u7d44\u307f\u8fbc\u307f\u30c7\u30a3\u30ec\u30af\u30c6\u30a3\u30d6* ngFor\u3092\u8ffd\u52a0\u3057\u3066&lt;li&gt;\u8981\u7d20\u3092\u5909\u66f4\u3057\u307e\u3059\u3002<\/p>\n<p><strong>app.component.ts (ngFor)<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">&lt;li *ngFor=&quot;let hero of heroes&quot;&gt;<\/pre>\n<p>&#8212;&#8212;-<br \/>\nngFor\u306e\u524d\u306b\u3042\u308b\u5148\u982d\u306e\u30a2\u30b9\u30bf\u30ea\u30b9\u30af\uff08*\uff09\u306f\u3001\u3053\u306e\u69cb\u6587\u306e\u91cd\u8981\u306a\u90e8\u5206\u3067\u3059\u3002<br \/>\n&#8212;&#8212;-<\/p>\n<p>&#8212;<br \/>\n\u30de\u30eb\u30c1\u30e9\u30a4\u30f3\u6587\u5b57\u5217\u306b\u5bfe\u3057\u3066\u306f\u30d0\u30c3\u30af\u30c6\u30a3\u30c3\u30af\u8a18\u6cd5\u3092\u518d\u5ea6\u4f7f\u7528\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u305d\u308c\u306f\u591a\u304f\u306e\u8a18\u8ff0\u3068\u306a\u3063\u3066\u3057\u307e\u3044\u307e\u3059\u3002<\/p>\n<p>\u3053\u3053\u306b\u793a\u3059\u3088\u3046\u306b\u30a4\u30f3\u30e9\u30a4\u30f3\u3067\u914d\u7f6e\u3059\u308b\u3053\u3068\u3082\u3001\u72ec\u81ea\u306e\u30d5\u30a1\u30a4\u30eb\u306b\u79fb\u52d5\u3057\u3066\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3092\u7c21\u5358\u306b\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0\u3059\u308b\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u5f8c\u306e\u7ae0\u3067\u3053\u308c\u3092\u884c\u3044\u307e\u3059\u3002\u4eca\u306e\u3068\u3053\u308d\u5727\u5ef6\u3092\u7d9a\u3051\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306b\u30b9\u30bf\u30a4\u30eb\u3092\u5272\u308a\u5f53\u3066\u308b\u3068\u304d\u3001\u305d\u306e\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306f\u305d\u306e\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306b\u9069\u7528\u3055\u308c\u307e\u3059\u3002<\/p>\n<p>\u79c1\u305f\u3061\u306e\u30b9\u30bf\u30a4\u30eb\u306fAppComponent\u306b\u306e\u307f\u9069\u7528\u3055\u308c\u3001\u5916\u5074\u306eHTML\u306b\u306f &#8220;\u30ea\u30fc\u30af&#8221;\u3057\u307e\u305b\u3093\u3002<\/p>\n<p>\u30d2\u30fc\u30ed\u30fc\u3092\u8868\u793a\u3059\u308b\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u306f\u6b21\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<br \/>\n&#8212;<\/p>\n<p>\u30d2\u30fc\u30ed\u30fc\u306e\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u5909\u6570\u3092\u4f7f\u7528\u3057\u3066\u30d2\u30fc\u30ed\u30fc\u306e\u30d7\u30ed\u30d1\u30c6\u30a3\u3092\u8868\u793a\u3059\u308b\u3001 &lt;li&gt;\u8981\u7d20\u306e\u9593\u306b\u3001\u3044\u304f\u3064\u304b\u306e\u30b3\u30f3\u30c6\u30f3\u30c4\u3092\u633f\u5165\u3057\u307e\u3059\u3002<\/p>\n<p><strong>app.component.ts (styled heroes)<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">&lt;li *ngFor=&quot;let hero of heroes&quot;&gt;\r\n  &lt;span class=&quot;badge&quot;&gt;{{hero.id}}&lt;\/span&gt; {{hero.name}}\r\n&lt;\/li&gt;<\/pre>\n<p>\u30d6\u30e9\u30a6\u30b6\u3092\u66f4\u65b0\u3059\u308b\u3068\u3001\u30d2\u30fc\u30ed\u30fc\u306e\u30ea\u30b9\u30c8\u304c\u8868\u793a\u3055\u308c\u307e\u3059\u3002<\/p>\n<h5>Styling our heroes<\/h5>\n<p>\u30d2\u30fc\u30ed\u30fc\u306e\u79c1\u9054\u306e\u30ea\u30b9\u30c8\u306f\u304b\u306a\u308a\u304b\u308f\u3044\u3089\u3057\u304f\u898b\u3048\u307e\u3059\u3002<\/p>\n<p>\u79c1\u305f\u3061\u306f\u3001\u30e6\u30fc\u30b6\u30fc\u304c\u3069\u306e\u3088\u3046\u306a\u30d2\u30fc\u30ed\u30fc\u3092\u9078\u3093\u3067\u3044\u308b\u306e\u304b\u3001\u307e\u305f \u3069\u306e\u30d2\u30fc\u30ed\u30fc\u304c\u9078\u629e\u3055\u308c\u3066\u3044\u308b\u306e\u304b\u3092\u8996\u899a\u7684\u306b\u660e\u78ba\u306b\u3057\u305f\u3044\u3068\u8003\u3048\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>@Component\u30c7\u30b3\u30ec\u30fc\u30bf\u306estyles\u30d7\u30ed\u30d1\u30c6\u30a3\u3092\u6b21\u306eCSS\u30af\u30e9\u30b9\u306b\u8a2d\u5b9a\u3059\u308b\u3053\u3068\u306b\u3088\u3063\u3066\u3001\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306b\u3044\u304f\u3064\u304b\u306e\u30b9\u30bf\u30a4\u30eb\u3092\u8ffd\u52a0\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<p><strong>app.component.ts (styles)<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">styles: &#x5B;`\r\n  .selected {\r\n    background-color: #CFD8DC !important;\r\n    color: white;\r\n  }\r\n  .heroes {\r\n    margin: 0 0 2em 0;\r\n    list-style-type: none;\r\n    padding: 0;\r\n    width: 15em;\r\n  }\r\n  .heroes li {\r\n    cursor: pointer;\r\n    position: relative;\r\n    left: 0;\r\n    background-color: #EEE;\r\n    margin: .5em;\r\n    padding: .3em 0;\r\n    height: 1.6em;\r\n    border-radius: 4px;\r\n  }\r\n  .heroes li.selected:hover {\r\n    background-color: #BBD8DC !important;\r\n    color: white;\r\n  }\r\n  .heroes li:hover {\r\n    color: #607D8B;\r\n    background-color: #DDD;\r\n    left: .1em;\r\n  }\r\n  .heroes .text {\r\n    position: relative;\r\n    top: -3px;\r\n  }\r\n  .heroes .badge {\r\n    display: inline-block;\r\n    font-size: small;\r\n    color: white;\r\n    padding: 0.8em 0.7em 0 0.7em;\r\n    background-color: #607D8B;\r\n    line-height: 1em;\r\n    position: relative;\r\n    left: -1px;\r\n    top: -4px;\r\n    height: 1.8em;\r\n    margin-right: .8em;\r\n    border-radius: 4px 0 0 4px;\r\n  }\r\n`]<\/pre>\n<p>\u8907\u6570\u884c\u306e\u6587\u5b57\u5217\u306b\u5bfe\u3057\u3066\u306f\u30d0\u30c3\u30af\u30c6\u30a3\u30c3\u30af\u8868\u8a18\u6cd5\u3092\u518d\u5ea6\u4f7f\u7528\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u3053\u3053\u306b\u793a\u3059\u3088\u3046\u306b\u30a4\u30f3\u30e9\u30a4\u30f3\u3067\u914d\u7f6e\u3059\u308b\u3053\u3068\u3082\u3001\u72ec\u81ea\u306e\u30d5\u30a1\u30a4\u30eb\u306b\u79fb\u52d5\u3057\u3066\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3092\u7c21\u5358\u306b\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0\u3059\u308b\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u5f8c\u306e\u7ae0\u3067\u3053\u308c\u3092\u884c\u3044\u307e\u3059\u3002\u4eca\u306e\u3068\u3053\u308d\u3053\u306e\u307e\u307e\u7d9a\u3051\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306b\u30b9\u30bf\u30a4\u30eb\u3092\u5272\u308a\u5f53\u3066\u308b\u3068\u304d\u3001\u305d\u306e\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306f\u305d\u306e\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306b\u9069\u7528\u3055\u308c\u307e\u3059\u3002<\/p>\n<p>\u79c1\u305f\u3061\u306e\u30b9\u30bf\u30a4\u30eb\u306fAppComponent\u306b\u306e\u307f\u9069\u7528\u3055\u308c\u3001\u5916\u5074\u306eHTML\u306b\u306f\u5f71\u97ff\u3057\u307e\u305b\u3093\u3002<\/p>\n<p>\u30d2\u30fc\u30ed\u30fc\u3092\u8868\u793a\u3059\u308b\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u306f\u6b21\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><strong>app.component.ts (styled heroes)<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">&lt;h2&gt;My Heroes&lt;\/h2&gt;\r\n&lt;ul class=&quot;heroes&quot;&gt;\r\n  &lt;li *ngFor=&quot;let hero of heroes&quot;&gt;\r\n    &lt;span class=&quot;badge&quot;&gt;{{hero.id}}&lt;\/span&gt; {{hero.name}}\r\n  &lt;\/li&gt;\r\n&lt;\/ul&gt;<\/pre>\n<h4>Selecting a Hero<\/h4>\n<p>\u30d2\u30fc\u30ed\u30fc\u306e\u30ea\u30b9\u30c8\u304c\u3042\u308a\u3001\u79c1\u305f\u3061\u306e\u30a2\u30d7\u30ea\u306b\u306f\u3072\u3068\u3064\u306e\u30d2\u30fc\u30ed\u30fc\u304c\u8868\u793a\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u30ea\u30b9\u30c8\u3068\u30b7\u30f3\u30b0\u30eb\u30d2\u30fc\u30ed\u30fc\u306f\u6c7a\u3057\u3066\u3064\u306a\u304c\u3063\u3066\u3044\u307e\u305b\u3093\u3002<\/p>\n<p>\u30e6\u30fc\u30b6\u30fc\u306f\u30ea\u30b9\u30c8\u304b\u3089\u30d2\u30fc\u30ed\u30fc\u3092\u9078\u629e\u3057\u3066\u3001\u9078\u629e\u3057\u305f\u30d2\u30fc\u30ed\u30fc\u3092\u8a73\u7d30\u30d3\u30e5\u30fc\u306b\u8868\u793a\u3055\u305b\u307e\u3059\u3002<\/p>\n<p>\u3053\u306eUI\u30d1\u30bf\u30fc\u30f3\u306f\u3001\u300cmaster-detail\u300d\u3068\u3057\u3066\u5e83\u304f\u77e5\u3089\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u79c1\u305f\u3061\u306e\u5834\u5408\u3001\u300cmaster\u300d\u306f\u3001\u30d2\u30fc\u30ed\u30fc\u30ea\u30b9\u30c8\u3067\u3042\u308a\u3001\u300cdetail\u300d\u306f\u9078\u629e\u3055\u308c\u305f\u30d2\u30fc\u30ed\u30fc\u3067\u3059\u3002<\/p>\n<p>\u30af\u30ea\u30c3\u30af\u30a4\u30d9\u30f3\u30c8\u306b\u30d0\u30a4\u30f3\u30c9\u3055\u308c\u305f\u3001selectedHero\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u30d7\u30ed\u30d1\u30c6\u30a3\u3092\u4f7f\u7528\u3057\u3066\u3001\u300cmaster\u300d\u3092\u300cdetail\u300d\u306b\u63a5\u7d9a\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<h5>Click event<\/h5>\n<ul>\n<li>Angle\u30a4\u30d9\u30f3\u30c8\u306e\u30d0\u30a4\u30f3\u30c9\u3092click\u30a4\u30d9\u30f3\u30c8\u306b\u633f\u5165\u3057\u3066\u3001&lt;li&gt;\u3092\u4fee\u6b63\u3057\u307e\u3059\u3002<strong>app.component.ts (template excerpt)<\/strong>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">&lt;li *ngFor=&quot;let hero of heroes&quot; (click)=&quot;onSelect(hero)&quot;&gt;\r\n  &lt;span class=&quot;badge&quot;&gt;{{hero.id}}&lt;\/span&gt; {{hero.name}}\r\n&lt;\/li&gt;<\/pre>\n<p><strong>\u30a4\u30d9\u30f3\u30c8\u30d0\u30a4\u30f3\u30c7\u30a3\u30f3\u30b0\u306b\u7126\u70b9\u3092\u5f53\u3066\u308b<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">(click)=\"onSelect(hero)\"<\/pre>\n<p>\u62ec\u5f27\u306f<\/li>\n<li>\u8981\u7d20\u306e\u30af\u30ea\u30c3\u30af\u30a4\u30d9\u30f3\u30c8\u3092\u30bf\u30fc\u30b2\u30c3\u30c8\u3068\u3057\u3066\u8b58\u5225\u3057\u307e\u3059\u3002\u7b49\u53f7\u306e\u53f3\u5074\u306b\u3042\u308b\u5f0f\u306fAppComponent\u30e1\u30bd\u30c3\u30c9\u306eonSelect\uff08\uff09\u3092\u547c\u3073\u51fa\u3057\u3001\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u5165\u529b\u5909\u6570hero\u3092\u5f15\u6570\u3068\u3057\u3066\u6e21\u3057\u307e\u3059\u3002\n<p>\u3053\u308c\u306fngFor\u3067\u4ee5\u524d\u5b9a\u7fa9\u3057\u305f\u306e\u3068\u540c\u3058\u30d2\u30fc\u30ed\u30fc\u5909\u6570\u3067\u3059\u3002<\/p>\n<p>&#8212;<br \/>\n<a href=\"https:\/\/angular.io\/docs\/ts\/latest\/guide\/user-input.html\">UserInput<\/a>\u3068<a href=\"https:\/\/angular.io\/docs\/ts\/latest\/guide\/template-syntax.html#event-binding\">Templating Syntax<\/a>\u306e\u7ae0\u3067\u30a4\u30d9\u30f3\u30c8\u30d0\u30a4\u30f3\u30c9\u306e\u8a73\u7d30\u3092\u5b66\u3093\u3067\u304f\u3060\u3055\u3044\u3002<br \/>\n&#8212;<\/p>\n<h5>Add the click handler<\/h5>\n<p>\u79c1\u305f\u3061\u306e\u30a4\u30d9\u30f3\u30c8\u30d0\u30a4\u30f3\u30c7\u30a3\u30f3\u30b0\u306f\u3001\u307e\u3060\u5b58\u5728\u3057\u306a\u3044onSelect\u30e1\u30bd\u30c3\u30c9\u3092\u6307\u3057\u307e\u3059\u3002<\/p>\n<p>\u3053\u306e\u30e1\u30bd\u30c3\u30c9\u3092\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306b\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n<p>\u305d\u306e\u884c\u3046\u306b\u306f\u3001\u4f55\u3092\u3059\u3079\u304d\u3067\u3057\u3087\u3046\u304b\uff1f<\/p>\n<p>\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u304c\u9078\u629e\u3057\u305f\u30d2\u30fc\u30ed\u30fc\u3092\u3001\u30e6\u30fc\u30b6\u30fc\u304c\u30af\u30ea\u30c3\u30af\u3057\u305f\u30d2\u30fc\u30ed\u30fc\u306b\u8a2d\u5b9a\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u79c1\u305f\u3061\u306e\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306b\u306f\u3001\u307e\u3060\u300c\u9078\u3070\u308c\u305f\u30d2\u30fc\u30ed\u30fc\u300d\u306f\u3042\u308a\u307e\u305b\u3093\u3002<\/p>\n<p>\u79c1\u305f\u3061\u306f\u305d\u3053\u304b\u3089\u59cb\u3081\u307e\u3059\u3002<\/p>\n<h5>Expose the selected hero<\/h5>\n<p>AppComponent\u306e\u9759\u7684\u30d2\u30fc\u30ed\u30fc\u30d7\u30ed\u30d1\u30c6\u30a3\u306f\u3082\u3046\u5fc5\u8981\u3042\u308a\u307e\u305b\u3093\u3002<\/p>\n<p>\u3053\u308c\u3092\u5358\u7d14\u306aselectedHero\u30d7\u30ed\u30d1\u30c6\u30a3\u306b\u7f6e\u304d\u63db\u3048\u307e\u3059\uff1a<\/p>\n<p><strong>app.component.ts (selectedHero)<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">selectedHero: Hero;<\/pre>\n<p>\u30e6\u30fc\u30b6\u30fc\u304c\u30d2\u30fc\u30ed\u30fc\u3092\u9078\u3076\u524d\u306b\u9078\u3093\u3060\u30d2\u30fc\u30ed\u30fc\u306f\u8ab0\u3082\u9078\u3093\u3067\u306f\u3044\u3051\u306a\u3044\u306e\u3067\u3001\u30d2\u30fc\u30ed\u30fc\u3068\u540c\u3058\u3088\u3046\u306bselectedHero\u3092\u521d\u671f\u5316\u3057\u306a\u3044\u3053\u3068\u306b\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>selectedHero\u30d7\u30ed\u30d1\u30c6\u30a3\u3092\u30e6\u30fc\u30b6\u30fc\u304c\u30af\u30ea\u30c3\u30af\u3057\u305f\u30d2\u30fc\u30ed\u30fc\u306b\u8a2d\u5b9a\u3059\u308bonSelect\u30e1\u30bd\u30c3\u30c9\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n<p><strong>app.component.ts (onSelect)<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">onSelect(hero: Hero): void {\r\n  this.selectedHero = hero;\r\n}<\/pre>\n<p><strong>app.component.ts (template excerpt)<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">&lt;h2&gt;{{selectedHero.name}} details!&lt;\/h2&gt;\r\n&lt;div&gt;&lt;label&gt;id: &lt;\/label&gt;{{selectedHero.id}}&lt;\/div&gt;\r\n&lt;div&gt;\r\n    &lt;label&gt;name: &lt;\/label&gt;\r\n    &lt;input &#x5B;(ngModel)]=&quot;selectedHero.name&quot; placeholder=&quot;name&quot;\/&gt;\r\n&lt;\/div&gt;<\/pre>\n<h5>Hide the empty detail with ngIf<\/h5>\n<p>\u30a2\u30d7\u30ea\u304c\u8aad\u307f\u8fbc\u307e\u308c\u308b\u3068\u30d2\u30fc\u30ed\u30fc\u306e\u30ea\u30b9\u30c8\u304c\u8868\u793a\u3055\u308c\u307e\u3059\u304c\u3001\u30d2\u30fc\u30ed\u30fc\u306f\u9078\u629e\u3055\u308c\u307e\u305b\u3093\u3002<\/p>\n<p>selectedHero\u306f\u672a\u5b9a\u7fa9\u3067\u3059\u3002\u305d\u306e\u305f\u3081\u3001\u30d6\u30e9\u30a6\u30b6\u306e\u30b3\u30f3\u30bd\u30fc\u30eb\u3067\u6b21\u306e\u30a8\u30e9\u30fc\u304c\u8868\u793a\u3055\u308c\u307e\u3059\u3002<\/p>\n<p>&#8212;<br \/>\nEXCEPTION: TypeError: Cannot read property &#8216;name&#8217; of undefined in [null]<br \/>\n&#8212;<\/p>\n<p>\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u306bselectedHero.name\u304c\u8868\u793a\u3055\u308c\u3066\u3044\u308b\u3053\u3068\u3092\u5fd8\u308c\u306a\u3044\u3067\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>selectedHero\u81ea\u4f53\u304c\u672a\u5b9a\u7fa9\u3067\u3042\u308b\u305f\u3081\u3001\u3053\u306ename\u30d7\u30ed\u30d1\u30c6\u30a3\u306f\u5b58\u5728\u3057\u307e\u305b\u3093\u3002<\/p>\n<p>\u9078\u3070\u308c\u305f\u30d2\u30fc\u30ed\u30fc\u304c\u5b58\u5728\u3059\u308b\u307e\u3067\u3001\u30d2\u30fc\u30ed\u30fc\u306e\u8a73\u7d30\u3092DOM\u304b\u3089\u5916\u3057\u3066\u304a\u304f\u3053\u3068\u3067\u3001\u3053\u306e\u554f\u984c\u306b\u5bfe\u51e6\u3057\u307e\u3059\u3002<\/p>\n<p>\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u306eHTML\u30d2\u30fc\u30ed\u30fc\u306e\u8a73\u7d30\u30b3\u30f3\u30c6\u30f3\u30c4\u3092<\/p>\n<div>\u3067\u56f2\u307f\u307e\u3059\u3002\u6b21\u306bngIf\u7d44\u8fbc\u307f\u30c7\u30a3\u30ec\u30af\u30c6\u30a3\u30d6\u3092\u8ffd\u52a0\u3057\u3001\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306eselectedHero\u30d7\u30ed\u30d1\u30c6\u30a3\u306b\u8a2d\u5b9a\u3057\u307e\u3059\u3002<br \/>\n<strong><br \/>\napp.component.ts (ngIf)<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">&lt;div *ngIf=&quot;selectedHero&quot;&gt;\r\n  &lt;h2&gt;{{selectedHero.name}} details!&lt;\/h2&gt;\r\n  &lt;div&gt;&lt;label&gt;id: &lt;\/label&gt;{{selectedHero.id}}&lt;\/div&gt;\r\n  &lt;div&gt;\r\n    &lt;label&gt;name: &lt;\/label&gt;\r\n    &lt;input &#x5B;(ngModel)]=&quot;selectedHero.name&quot; placeholder=&quot;name&quot;\/&gt;\r\n  &lt;\/div&gt;\r\n&lt;\/div&gt;<\/pre>\n<p>&#8212;<br \/>\nngIf\u306e\u524d\u306b\u3042\u308b\u5148\u982d\u306e\u30a2\u30b9\u30bf\u30ea\u30b9\u30af\uff08*\uff09\u306f\u3053\u306e\u69cb\u6587\u306e\u91cd\u8981\u306a\u90e8\u5206\u3067\u3059\u3002<br \/>\n&#8212;<\/p>\n<p>selectedHero\u304c\u306a\u3044\u5834\u5408\u3001ngIf\u30c7\u30a3\u30ec\u30af\u30c6\u30a3\u30d6\u306f\u30d2\u30fc\u30ed\u30fc\u306e\u8a73\u7d30HTML\u3092DOM\u304b\u3089\u524a\u9664\u3057\u307e\u3059\u3002<\/p>\n<p>\u30d2\u30fc\u30ed\u30fc\u306e\u8a73\u7d30\u8981\u7d20\u306f\u306a\u304f\u3001\u62d8\u675f\u529b\u306f\u3042\u308a\u307e\u305b\u3093\u3002<\/p>\n<p>\u30e6\u30fc\u30b6\u30fc\u304c\u30d2\u30fc\u30ed\u30fc\u3092\u9078\u629e\u3059\u308b\u3068\u3001selectedHero\u306f\u300ctrue\u300d\u306b\u306a\u308a\u3001ngIf\u306f\u30d2\u30fc\u30ed\u30fc\u306e\u8a73\u7d30\u30b3\u30f3\u30c6\u30f3\u30c4\u3092DOM\u306b\u5165\u308c\u3001\u30cd\u30b9\u30c8\u3055\u308c\u305f\u30d0\u30a4\u30f3\u30c7\u30a3\u30f3\u30b0\u3092\u8a55\u4fa1\u3057\u307e\u3059\u3002<\/p>\n<p>&#8212;<br \/>\nngIf\u3068ngFor\u306f\u3001DOM\u306e\u4e00\u90e8\u306e\u69cb\u9020\u3092\u5909\u66f4\u3067\u304d\u308b\u305f\u3081\u3001\u69cb\u9020\u30c7\u30a3\u30ec\u30af\u30c6\u30a3\u30d6\u3068\u547c\u3070\u308c\u307e\u3059\u3002\u8a00\u3044\u63db\u3048\u308c\u3070\u3001Angular\u306fDOM\u5185\u306e\u30b3\u30f3\u30c6\u30f3\u30c4\u3092\u8868\u793a\u3059\u308b\u65b9\u6cd5\u306b\u69cb\u9020\u3092\u4e0e\u3048\u307e\u3059\u3002<\/p>\n<p>ngIf\u3001ngFor\u3001\u305d\u306e\u4ed6\u306e\u69cb\u9020\u30c7\u30a3\u30ec\u30af\u30c6\u30a3\u30d6\u306e\u8a73\u7d30\u306b\u3064\u3044\u3066\u306f\u3001<a href=\"https:\/\/angular.io\/docs\/ts\/latest\/guide\/structural-directives.html\">Structural Directives<\/a>\u3068<a href=\"https:\/\/angular.io\/docs\/ts\/latest\/guide\/template-syntax.html#directives\">Template Syntax<\/a>\u306e\u7ae0\u3092\u53c2\u7167\u3057\u3066\u304f\u3060\u3055\u3044\u3002<br \/>\n&#8212;<\/p>\n<p>\u30d6\u30e9\u30a6\u30b6\u304c\u66f4\u65b0\u3055\u308c\u3001\u82f1\u96c4\u306e\u30ea\u30b9\u30c8\u304c\u8868\u793a\u3055\u308c\u307e\u3059\u304c\u3001\u9078\u629e\u3055\u308c\u305f\u30d2\u30fc\u30ed\u30fc\u306e\u8a73\u7d30\u306f\u8868\u793a\u3055\u308c\u307e\u305b\u3093\u3002<\/p>\n<p>ngIf\u306f\u3001selectedHero\u304c\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u306a\u3044\u9650\u308a\u3001DOM\u304b\u3089\u305d\u308c\u3092\u4fdd\u6301\u3057\u307e\u3059\u3002<\/p>\n<p>\u30ea\u30b9\u30c8\u5185\u306e\u30d2\u30fc\u30ed\u30fc\u3092\u30af\u30ea\u30c3\u30af\u3059\u308b\u3068\u3001\u9078\u629e\u3055\u308c\u305f\u30d2\u30fc\u30ed\u30fc\u304c\u30d2\u30fc\u30ed\u30fc\u306e\u8a73\u7d30\u306b\u8868\u793a\u3055\u308c\u307e\u3059\u3002\u79c1\u305f\u3061\u304c\u671f\u5f85\u3059\u308b\u3088\u3046\u306b\u3059\u3079\u3066\u304c\u50cd\u3044\u3066\u3044\u307e\u3059\u3002<\/p>\n<h5>Styling the selection<\/h5>\n<p>\u79c1\u305f\u3061\u306f\u4e0b\u8a18\u306e\u8a73\u7d30\u30a8\u30ea\u30a2\u3067\u9078\u629e\u3055\u308c\u305f\u30d2\u30fc\u30ed\u30fc\u3092\u898b\u307e\u3059\u304c\u3001\u4e0a\u8a18\u306e\u30d2\u30fc\u30ed\u30fc\u3092\u3059\u3050\u306b\u898b\u3064\u3051\u308b\u3053\u3068\u306f\u3067\u304d\u307e\u305b\u3093\u3002<\/p>\n<p>\u9078\u629e\u3057\u305fCSS\u30af\u30e9\u30b9\u3092\u30de\u30b9\u30bf\u30fc\u30ea\u30b9\u30c8\u306e\u9069\u5207\u306a<\/p>\n<\/div>\n<\/li>\n<li>\u306b\u9069\u7528\u3059\u308b\u3053\u3068\u3067\u3001\u4fee\u6b63\u3067\u304d\u307e\u3059\u3002\u305f\u3068\u3048\u3070\u3001\u30d2\u30fc\u30ed\u30fc\u30ea\u30b9\u30c8\u304b\u3089Magneta\u3092\u9078\u629e\u3059\u308b\u3068\u3001\u3053\u3053\u306b\u793a\u3059\u3088\u3046\u306b\u5fae\u5999\u306a\u80cc\u666f\u8272\u3092\u4ed8\u3051\u308b\u3053\u3068\u3067\u8996\u899a\u7684\u306b\u30dd\u30c3\u30d7\u30a2\u30a6\u30c8\u3055\u305b\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7581\" src=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/heroes-list-selected.png\" alt=\"heroes-list-selected\" width=\"165\" height=\"129\" \/><\/p>\n<p>\u9078\u629e\u3057\u305f\u30af\u30e9\u30b9\u306e\u30af\u30e9\u30b9\u306e\u30d7\u30ed\u30d1\u30c6\u30a3\u30d0\u30a4\u30f3\u30c7\u30a3\u30f3\u30b0\u3092\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u306b\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n<p>\u3053\u308c\u3092\u3001\u73fe\u5728\u9078\u629e\u3055\u308c\u3066\u3044\u308b\u30d2\u30fc\u30ed\u30fc\u3068\u30d2\u30fc\u30ed\u30fc\u3092\u6bd4\u8f03\u3059\u308b\u5f0f\u306b\u8a2d\u5b9a\u3057\u307e\u3059\u3002<\/p>\n<p>\u30ad\u30fc\u306f\u3001CSS\u30af\u30e9\u30b9\uff08\u9078\u629e\u6e08\u307f\uff09\u306e\u540d\u524d\u3067\u3059\u3002 2\u3064\u306e\u30d2\u30fc\u30ed\u30fc\u304c\u4e00\u81f4\u3059\u308b\u5834\u5408\u306ftrue\u3001\u305d\u3046\u3067\u306a\u3044\u5834\u5408\u306ffalse\u3067\u3059\u3002<\/p>\n<p>\u300c\u30d2\u30fc\u30ed\u30fc\u304c\u4e00\u81f4\u3059\u308c\u3070\u9078\u629e\u3057\u305f\u30af\u30e9\u30b9\u3092\u9069\u7528\u3057\u3001\u305d\u3046\u3067\u306a\u3051\u308c\u3070\u524a\u9664\u3059\u308b\u300d\u3068\u8a00\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<p><strong>app.component.ts (setting the CSS class)<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">&#x5B;class.selected]=\"hero === selectedHero\"<\/pre>\n<p>\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3067class.selected\u304c\u89d2\u304b\u3063\u3053\uff08[]\uff09\u3067\u56f2\u307e\u308c\u3066\u3044\u308b\u3053\u3068\u306b\u6ce8\u76ee\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>\u3053\u308c\u306f\u3001\u30d7\u30ed\u30d1\u30c6\u30a3\u30d0\u30a4\u30f3\u30c7\u30a3\u30f3\u30b0\u306e\u69cb\u6587\u3067\u3059\u3002<\/p>\n<p>\u30c7\u30fc\u30bf\u304c\u30c7\u30fc\u30bf\u30bd\u30fc\u30b9\uff08expression hero === selectedHero\uff09\u304b\u3089\u30af\u30e9\u30b9\u306e\u30d7\u30ed\u30d1\u30c6\u30a3\u3078\u4e00\u65b9\u5411\u306b\u6d41\u308c\u308b\u30d0\u30a4\u30f3\u30c7\u30a3\u30f3\u30b0\u3067\u3059\u3002<\/p>\n<p><strong>app.component.ts (styling each hero)<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">&lt;li *ngFor=&quot;let hero of heroes&quot;\r\n  &#x5B;class.selected]=&quot;hero === selectedHero&quot;\r\n  (click)=&quot;onSelect(hero)&quot;&gt;\r\n  &lt;span class=&quot;badge&quot;&gt;{{hero.id}}&lt;\/span&gt; {{hero.name}}\r\n&lt;\/li&gt;<\/pre>\n<p>&#8212;<br \/>\nLearn more about property bindings in the Template Syntax chapter.<br \/>\n&#8212;<\/p>\n<p>\u30d6\u30e9\u30a6\u30b6\u304c\u30a2\u30d7\u30ea\u3092\u30ea\u30ed\u30fc\u30c9\u3057\u307e\u3059\u3002\u79c1\u305f\u3061\u306f\u4e3b\u4eba\u516cMagneta\u3092\u9078\u629e\u3057\u3001\u305d\u306e\u9078\u629e\u306f\u80cc\u666f\u8272\u306b\u3088\u3063\u3066\u660e\u78ba\u306b\u8b58\u5225\u3055\u308c\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7582\" src=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/heroes-list-1.png\" alt=\"heroes-list-1\" width=\"220\" height=\"540\" srcset=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/heroes-list-1.png 220w, https:\/\/www.webcyou.com\/wp-content\/uploads\/heroes-list-1-122x300.png 122w\" sizes=\"auto, (max-width: 220px) 100vw, 220px\" \/><\/p>\n<p>\u79c1\u305f\u3061\u306f\u5225\u306e\u30d2\u30fc\u30ed\u30fc\u3092\u9078\u629e\u3057\u3001\u305d\u306e\u30d2\u30fc\u30ed\u30fc\u306b\u5fe0\u5b9f\u306a\u8272\u306e\u5207\u308a\u66ff\u3048\u3092\u884c\u3044\u307e\u3059\u3002<\/p>\n<p>\u3053\u3053\u306b\u306f\u5b8c\u5168\u306aapp.component.ts\u304c\u3042\u308a\u307e\u3059<\/p>\n<p><strong>app.component.ts<\/strong><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">import { Component } from '@angular\/core';\r\nexport class Hero {\r\n  id: number;\r\n  name: string;\r\n}\r\nconst HEROES: Hero&#x5B;] = &#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@Component({\r\n  selector: 'my-app',\r\n  template: `\r\n    &lt;h1&gt;{{title}}&lt;\/h1&gt;\r\n    &lt;h2&gt;My Heroes&lt;\/h2&gt;\r\n    &lt;ul class=&quot;heroes&quot;&gt;\r\n      &lt;li *ngFor=&quot;let hero of heroes&quot;\r\n        &#x5B;class.selected]=&quot;hero === selectedHero&quot;\r\n        (click)=&quot;onSelect(hero)&quot;&gt;\r\n        &lt;span class=&quot;badge&quot;&gt;{{hero.id}}&lt;\/span&gt; {{hero.name}}\r\n      &lt;\/li&gt;\r\n    &lt;\/ul&gt;\r\n    &lt;div *ngIf=&quot;selectedHero&quot;&gt;\r\n      &lt;h2&gt;{{selectedHero.name}} details!&lt;\/h2&gt;\r\n      &lt;div&gt;&lt;label&gt;id: &lt;\/label&gt;{{selectedHero.id}}&lt;\/div&gt;\r\n      &lt;div&gt;\r\n        &lt;label&gt;name: &lt;\/label&gt;\r\n        &lt;input &#x5B;(ngModel)]=&quot;selectedHero.name&quot; placeholder=&quot;name&quot;\/&gt;\r\n      &lt;\/div&gt;\r\n    &lt;\/div&gt;\r\n  `,\r\n  styles: &#x5B;`\r\n    .selected {\r\n      background-color: #CFD8DC !important;\r\n      color: white;\r\n    }\r\n    .heroes {\r\n      margin: 0 0 2em 0;\r\n      list-style-type: none;\r\n      padding: 0;\r\n      width: 15em;\r\n    }\r\n    .heroes li {\r\n      cursor: pointer;\r\n      position: relative;\r\n      left: 0;\r\n      background-color: #EEE;\r\n      margin: .5em;\r\n      padding: .3em 0;\r\n      height: 1.6em;\r\n      border-radius: 4px;\r\n    }\r\n    .heroes li.selected:hover {\r\n      background-color: #BBD8DC !important;\r\n      color: white;\r\n    }\r\n    .heroes li:hover {\r\n      color: #607D8B;\r\n      background-color: #DDD;\r\n      left: .1em;\r\n    }\r\n    .heroes .text {\r\n      position: relative;\r\n      top: -3px;\r\n    }\r\n    .heroes .badge {\r\n      display: inline-block;\r\n      font-size: small;\r\n      color: white;\r\n      padding: 0.8em 0.7em 0 0.7em;\r\n      background-color: #607D8B;\r\n      line-height: 1em;\r\n      position: relative;\r\n      left: -1px;\r\n      top: -4px;\r\n      height: 1.8em;\r\n      margin-right: .8em;\r\n      border-radius: 4px 0 0 4px;\r\n    }\r\n  `]\r\n})\r\nexport class AppComponent {\r\n  title = 'Tour of Heroes';\r\n  heroes = HEROES;\r\n  selectedHero: Hero;\r\n  onSelect(hero: Hero): void {\r\n    this.selectedHero = hero;\r\n  }\r\n}<\/pre>\n<h4>The Road We\u2019ve Travelled<\/h4>\n<p>\u3053\u306e\u7ae0\u3067\u306f\u3001\u6b21\u306e\u3088\u3046\u306a\u3053\u3068\u3092\u9054\u6210\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u30fb \u79c1\u305f\u3061\u306e\u30d2\u30fc\u30ed\u30fc\u30c4\u30a2\u30fc\u3067\u306f\u3001\u9078\u629e\u53ef\u80fd\u306a\u30d2\u30fc\u30ed\u30fc\u306e\u30ea\u30b9\u30c8\u304c\u8868\u793a\u3055\u308c\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f<\/p>\n<p>\u30fb \u30d2\u30fc\u30ed\u30fc\u3092\u9078\u3093\u3067\u30d2\u30fc\u30ed\u30fc\u306e\u8a73\u7d30\u3092\u8868\u793a\u3059\u308b\u6a5f\u80fd\u3092\u8ffd\u52a0\u3057\u307e\u3057\u305f<\/p>\n<p>\u30fb \u7d44\u307f\u8fbc\u307f\u30c7\u30a3\u30ec\u30af\u30c6\u30a3\u30d6ngIf\u3068ngFor\u3092\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306e\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3067\u4f7f\u7528\u3059\u308b\u65b9\u6cd5\u3092\u5b66\u3073\u307e\u3057\u305f<\/p>\n<p>Run the <a href=\"https:\/\/angular.io\/resources\/live-examples\/toh-2\/ts\/eplnkr.html\">live example<\/a> for this part.<\/p>\n<h5>The Road Ahead<\/h5>\n<p>\u79c1\u305f\u3061\u306e\u30d2\u30fc\u30ed\u30fc\u30c4\u30a2\u30fc\u306f\u6210\u9577\u3057\u307e\u3057\u305f\u304c\u3001\u305d\u308c\u306f\u5b8c\u5168\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002<\/p>\n<p>\u30a2\u30d7\u30ea\u5168\u4f53\u3092\u5358\u4e00\u306e\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306b\u307e\u3068\u3081\u308b\u3053\u3068\u306f\u3067\u304d\u307e\u305b\u3093\u3002\u79c1\u305f\u3061\u306f\u305d\u308c\u3092\u30b5\u30d6\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306b\u5206\u89e3\u3057\u3001\u6b21\u306e\u7ae0\u3067\u5b66\u3076\u3088\u3046\u306b\u4e00\u7dd2\u306b\u50cd\u304f\u3088\u3046\u306b\u6559\u3048\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<h5>\u6b21\u306eSTEP<\/h5>\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><\/li>\n<li>\n<div><\/div>\n<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>MASTER\/DETAIL \u3053\u3061\u3089\u306e\u30da\u30fc\u30b8\u306f\u3001\u3053\u3061\u3089\u306e\u30da\u30fc\u30b8\u306e\u7c21\u5358\u306a\u548c\u8a33\u3067\u3059\u3002 Angular2 tutorial | MASTER\/DETAIL \u305d\u306e\u4ed6 Angular2\u306e\u59cb\u3081\u65b9\u3002Angular2 \u516c\u5f0f\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[203],"tags":[73,172,171,59,167,177,168,176,37,47,179,50,169,107,180,150,44,45,39,178,78,114,118],"class_list":{"0":"post-7512","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"hentry","6":"category-angular2","7":"tag-actiinscript2-0","8":"tag-actionscript","9":"tag-android","10":"tag-android-sdk","11":"tag-css","12":"tag-css3","13":"tag-html","14":"tag-html5","15":"tag-iphone-","16":"tag-javascript-2","17":"tag-jquery","18":"tag-jquery-mobile","19":"tag-mac","20":"tag-mamp","21":"tag-mysql","22":"tag-vagrant","23":"tag-web","25":"tag-39","26":"tag-178","27":"tag-78","28":"tag-114","29":"tag-118"},"_links":{"self":[{"href":"https:\/\/www.webcyou.com\/index.php?rest_route=\/wp\/v2\/posts\/7512","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=7512"}],"version-history":[{"count":11,"href":"https:\/\/www.webcyou.com\/index.php?rest_route=\/wp\/v2\/posts\/7512\/revisions"}],"predecessor-version":[{"id":10159,"href":"https:\/\/www.webcyou.com\/index.php?rest_route=\/wp\/v2\/posts\/7512\/revisions\/10159"}],"wp:attachment":[{"href":"https:\/\/www.webcyou.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7512"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webcyou.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7512"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webcyou.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7512"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}