1- # The Hero Editor
1+ {@a the-hero-editor}
2+ # ヒーローエディター
23
3- The application now has a basic title.
4- Next you will create a new component to display hero information
5- and place that component in the application shell.
4+ アプリケーションに基本的なタイトルが追加されました。
5+ 次に、ヒーロー情報を表示するための新しいコンポーネントを作成し、
6+ そのコンポーネントをアプリケーションシェルに配置します。
67
7- ## Create the heroes component
8+ {@a create-the-heroes-component}
9+ ## heroes コンポーネントを作成する
810
9- Using the Angular CLI, generate a new component named ` heroes ` .
11+ Angular CLIを使用して、 ` heroes ` という名前の新しいコンポーネントを生成します。
1012
1113<code-example language =" sh " class =" code-shell " >
1214 ng generate component heroes
1315</code-example >
1416
15- The CLI creates a new folder, ` src/app/heroes/ ` and generates
16- the three files of the ` HeroesComponent ` .
17+ CLIは ` src/app/heroes/ ` という新しいフォルダを作成し、
18+ ` HeroesComponent ` に関する3つのファイルを生成します。
1719
18- The ` HeroesComponent ` class file is as follows:
20+ ` HeroesComponent ` のクラスファイルは次のとおりです。
1921
2022<code-example
2123 path="toh-pt1/src/app/heroes/heroes.component.ts" region="v1"
22- title="app/heroes/heroes.component.ts (initial version )" linenums="false">
24+ title="app/heroes/heroes.component.ts (初期バージョン )" linenums="false">
2325</code-example >
2426
25- You always import the ` Component ` symbol from the Angular core library
26- and annotate the component class with ` @Component ` .
27+ 常にAngularコアライブラリから ` Component ` シンボルをインポートし、
28+ コンポーネントクラスに ` @Component ` で注釈を付けます。
2729
28- ` @Component ` is a decorator function that specifies the Angular metadata for the component.
30+ ` @Component ` は、コンポーネントのAngularメタデータを指定するデコレータ関数です。
2931
30- The CLI generated three metadata properties :
32+ CLIは3つのメタデータプロパティを生成しました :
3133
32- 1 . ` selector ` &mdash ; the components CSS element selector
33- 1 . ` templateUrl ` &mdash ; the location of the component's template file.
34- 1 . ` styleUrls ` &mdash ; the location of the component's private CSS styles.
34+ 1 . ` selector ` &mdash ; コンポーネントのCSS要素セレクタ
35+ 1 . ` templateUrl ` &mdash ; コンポーネントのテンプレートファイルの場所
36+ 1 . ` styleUrls ` &mdash ; コンポーネントのプライベートCSSスタイルの場所
3537
3638{@a selector}
3739
38- The [ CSS element selector ] ( https://developer.mozilla.org/en-US/docs/Web/CSS/Type_selectors ) ,
39- ` 'app-heroes' ` , matches the name of the HTML element that identifies this component within a parent component's template.
40+ [ CSS要素セレクタ ] ( https://developer.mozilla.org/en-US/docs/Web/CSS/Type_selectors ) である
41+ ` 'app-heroes' ` は、親コンポーネントのテンプレート内でこのコンポーネントを識別するHTML要素の名前と一致します。
4042
41- The ` ngOnInit ` is a [ lifecycle hook ] ( guide/lifecycle-hooks#oninit )
42- Angular calls ` ngOnInit ` shortly after creating a component.
43- It's a good place to put initialization logic.
43+ ` ngOnInit ` は [ ライフサイクルフック ] ( guide/lifecycle-hooks#oninit ) です。
44+ Angularは、コンポーネントの作成直後に ` ngOnInit ` を呼び出します。
45+ 初期化ロジックを置くのに適しています。
4446
45- Always ` export ` the component class so you can ` import ` it elsewhere ... like in the ` AppModule ` .
47+ 常にコンポーネントクラスを ` export ` するので、 ` AppModule ` のようにいつでも他の場所に ` import ` できます。
4648
47- ### Add a _ hero_ property
49+ {@a add-a-hero-property}
50+ ### _ hero_ プロパティを追加する
4851
49- Add a ` hero ` property to the ` HeroesComponent ` for a hero named "Windstorm."
52+ "Windstorm"という名前のヒーローのために、 ` HeroesComponent ` に ` hero ` プロパティを追加します。
5053
51- <code-example path =" toh-pt1/src/app/heroes/heroes.component.ts " region =" add-hero " title =" heroes.component.ts (hero property ) " linenums =" false " >
54+ <code-example path =" toh-pt1/src/app/heroes/heroes.component.ts " region =" add-hero " title =" heroes.component.ts (hero プロパティ ) " linenums =" false " >
5255</code-example >
5356
54- ### Show the hero
57+ {@a show-the-hero}
58+ ### ヒーローを表示する
5559
56- Open the ` heroes.component.html ` template file.
57- Delete the default text generated by the Angular CLI and
58- replace it with a data binding to the new ` hero ` property.
60+ ` heroes.component.html ` テンプレートファイルを開きます。
61+ Angular CLIで生成されたデフォルトのテキストを削除し、
62+ それを新しい ` hero ` プロパティへのデータバインディングに置き換えてください。
5963
6064<code-example path =" toh-pt1/src/app/heroes/heroes.component.1.html " title =" heroes.component.html " region =" show-hero-1 " linenums =" false " >
6165</code-example >
6266
63- ## Show the _ HeroesComponent_ view
67+ {@a show-the-heroescomponent-view}
68+ ## _ HeroesComponent_ ビューを表示する
6469
65- To display the ` HeroesComponent ` , you must add it to the template of the shell ` AppComponent ` .
70+ ` HeroesComponent ` を表示するには、それをアプリケーションシェルの ` AppComponent ` のテンプレートに追加する必要があります。
6671
67- Remember that ` app-heroes ` is the [ element selector ] ( #selector ) for the ` HeroesComponent ` .
68- So add an ` <app-heroes> ` element to the ` AppComponent ` template file, just below the title.
72+ ` app-heroes ` は ` HeroesComponent ` の [ 要素セレクタ ] ( #selector ) であることを思い出してください。
73+ なので、 ` AppComponent ` のテンプレートファイルで、タイトルの直下に ` <app-heroes> ` 要素を追加してください。
6974
7075<code-example path =" toh-pt1/src/app/app.component.html " title =" src/app/app.component.html " linenums =" false " >
7176</code-example >
7277
73- Assuming that the CLI ` ng serve ` command is still running,
74- the browser should refresh and display both the application title and the hero name.
78+ CLIの ` ng serve ` コマンドがまだ実行中であれば、
79+ ブラウザが更新され、アプリケーションのタイトルとヒーローの名前が表示されます。
7580
76- ## Create a Hero class
81+ {@a create-a-hero-class}
82+ ## Hero クラスを作成する
7783
78- A real hero is more than a name.
84+ 本当のヒーローは名前だけではありません。
7985
80- Create a ` Hero ` class in its own file in the ` src/app ` folder.
81- Give it ` id ` and ` name ` properties.
86+ ` src/app ` フォルダ内の独自のファイルに、 ` Hero ` クラスを作成します。
87+ それに ` id ` プロパティと ` name ` プロパティを与えます。
8288
8389<code-example path =" toh-pt1/src/app/hero.ts " title =" src/app/hero.ts " linenums =" false " >
8490</code-example >
8591
8692
87- Return to the ` HeroesComponent ` class and import the ` Hero ` class.
93+ ` HeroesComponent ` クラスに戻り、 ` Hero ` クラスをインポートします。
8894
89- Refactor the component's ` hero ` property to be of type ` Hero ` .
90- Initialize it with an ` id ` of ` 1 ` and the name ` Windstorm ` .
95+ コンポーネントの ` hero ` プロパティを ` Hero ` 型にリファクタリングします。
96+ それを、 ` 1 ` という ` id ` と ` Windstorm ` という名前で初期化します。
9197
92- The revised ` HeroesComponent ` class file should look like this:
98+ 改訂された ` HeroesComponent ` のクラスファイルは、次のようになります。
9399
94100<code-example path="toh-pt1/src/app/heroes/heroes.component.ts" linenums="false"
95101 title= "src/app/heroes/heroes.component.ts">
96102</code-example >
97103
98- The page no longer displays properly because you changed the hero from a string to an object.
104+ ヒーローを文字列からオブジェクトに変更したため、ページが正しく表示されなくなりました。
99105
100- ## Show the hero object
106+ {@a show-the-hero-object}
107+ ## ヒーローオブジェクトを表示する
101108
102- Update the binding in the template to announce the hero's name
103- and show both ` id ` and ` name ` in a details layout like this:
109+ ヒーローの名前を知らせるためにテンプレートのバインディングを更新し、
110+ 次のような詳細レイアウトで ` id ` と ` name ` の両方を表示します。
104111
105112<code-example
106113 path="toh-pt1/src/app/heroes/heroes.component.1.html"
107114 region="show-hero-2"
108- title="heroes.component.html (HeroesComponent's template )" linenums="false">
115+ title="heroes.component.html (HeroesComponent のテンプレート )" linenums="false">
109116</code-example >
110117
111- The browser refreshes and display's the hero's information.
118+ ブラウザが更新され、ヒーローの情報が表示されます。
112119
113- ## Format with the _ UppercasePipe_
120+ {@a format-with-the-uppercasepipe}
121+ ## _ UppercasePipe_ で書式設定する
114122
115- Modify the ` hero.name ` binding like this.
123+ ` hero.name ` のバインディングをこのように修正してください。
116124<code-example
117125 path="toh-pt1/src/app/heroes/heroes.component.html"
118126 region="pipe">
119127</code-example >
120128
121- The browser refreshes and now the hero's name is displayed in capital letters.
129+ ブラウザが更新され、ヒーローの名前が大文字で表示されるようになります。
122130
123- The word ` uppercase ` in the interpolation binding,
124- right after the pipe operator ( | ),
125- activates the built-in ` UppercasePipe ` .
131+ 補間バインディングの中、パイプ演算子 ( | ) の直後にある単語` uppercase ` は、
132+ 組み込みの` UppercasePipe ` を起動します。
126133
127- [ Pipes ] ( guide/pipes ) are a good way to format strings, currency amounts, dates and other display data.
128- Angular ships with several built-in pipes and you can create your own.
134+ [ パイプ ] ( guide/pipes ) は、文字列、通貨金額、日付や、その他の表示データを書式設定するのに適しています。
135+ Angularは複数のビルトインパイプを備えており、あなた自身が独自のパイプを作ることもできます。
129136
130- ## Edit the hero
137+ {@a edit-the-hero}
138+ ## ヒーローを編集する
131139
132- Users should be able to edit the hero name in an ` <input> ` textbox.
140+ ユーザーは ` <input> ` テキストボックスでヒーローの名前を編集できるべきです。
133141
134- The textbox should both _ display _ the hero's ` name ` property
135- and _ update _ that property as the user types.
136- That means data flow from the component class _ out to the screen _ and
137- from the screen _ back to the class _ .
142+ テキストボックスにはヒーローの ` name ` プロパティが _ 表示 _ され、
143+ ユーザーの入力時にそのプロパティが _ 更新 _ されます。
144+ これは、コンポーネントクラスから _ 画面へ _ 、
145+ そして画面から _ コンポーネントクラスへの _ データフローを意味します。
138146
139- To automate that data flow, setup a two-way data binding between the ` <input> ` form element and the ` hero.name ` property.
147+ そのデータフローを自動化するには、 ` <input> ` フォーム要素と ` hero.name ` プロパティとの間に双方向データバインディングを設定します。
140148
141- ### Two-way binding
149+ {@a two-way-binding}
150+ ### 双方向データバインディング
142151
143- Refactor the details area in the ` HeroesComponent ` template so it looks like this:
152+ ` HeroesComponent ` テンプレートの詳細エリアをリファクタリングすると、次のようになります。
144153
145- <code-example path =" toh-pt1/src/app/heroes/heroes.component.1.html " region =" name-input " title =" src/app/heroes/heroes.component.html (HeroesComponent's template ) " linenums =" false " >
154+ <code-example path =" toh-pt1/src/app/heroes/heroes.component.1.html " region =" name-input " title =" src/app/heroes/heroes.component.html (HeroesComponent のテンプレート ) " linenums =" false " >
146155
147156</code-example >
148157
149- ** [ (ngModel)] ** is Angular's two-way data binding syntax.
158+ ** [ (ngModel)] ** は、Angularの双方向データバインディング構文です。
150159
151- Here it binds the ` hero.name ` property to the HTML textbox so that data can flow _ in both directions:_ from the ` hero.name ` property to the textbox, and from the textbox back to the ` hero.name ` .
160+ これで` hero.name ` プロパティをHTMLのテキストボックスにバインドするので、
161+ ` hero.name ` プロパティからテキストボックスへ、テキストボックスから` hero.name ` プロパティへ、 _ 双方向に_ データを流すことができます。
152162
153- ### The missing _ FormsModule_
163+ {@a the-missing-formsmodule}
164+ ### 見つからない _ FormsModule_
154165
155- Notice that the app stopped working when you added ` [(ngModel)] ` .
166+ ` [(ngModel)] ` を追加したときにアプリケーションが動かなくなったことに注目してください。
156167
157- To see the error, open the browser development tools and look in the console
158- for a message like
168+ エラーを表示するには、ブラウザの開発ツールを開き、
169+ コンソールで次のようなメッセージを探します、
159170
160171<code-example language =" sh " class =" code-shell " >
161172Template parse errors:
162173Can't bind to 'ngModel' since it isn't a known property of 'input'.
163174</code-example >
164175
165- Although ` ngModel ` is a valid Angular directive, it isn't available by default.
176+ ` ngModel ` は有効なAngularディレクティブですが、デフォルトでは使用できません。
166177
167- It belongs to the optional ` FormsModule ` and you must _ opt-in _ to using it.
178+ これはオプションの ` FormsModule ` に属しており、使用するにはそのモジュールをオプトインする必要があります。
168179
169180## _ AppModule_
170181
171- Angular needs to know how the pieces of your application fit together
172- and what other files and libraries the app requires.
173- This information is called _ metadata _
182+ Angularでは、アプリケーションの部品がどのように合わさるかや、
183+ アプリケーションが必要としている他のファイルやライブラリを知る必要があります。
184+ この情報を _ メタデータ _ といいます。
174185
175- Some of the metadata is in the ` @Component ` decorators that you added to your component classes.
176- Other critical metadata is in [ ` @NgModule ` ] ( guide/ngmodule ) decorators.
186+ 一部のメタデータは、コンポーネントクラスに追加した ` @Component ` デコレータ内にあります。
187+ その他の重要なメタデータは [ ` @NgModule ` ] ( guide/ngmodule ) デコレータ内にあります。
177188
178- The most important ` @NgModule ` decorator annotates the top-level ** AppModule** class.
189+ 最も重要な ` @NgModule ` デコレータは、トップレベルの ** AppModule** クラスに注釈を付けます。
179190
180- The Angular CLI generated an ` AppModule ` class in ` src/app/app.module.ts ` when it created the project.
181- This is where you _ opt-in _ to the ` FormsModule ` .
191+ Angular CLI は、プロジェクトを作成するときに ` src/app/app.module.ts ` に ` AppModule ` クラスを作成しました。
192+ ここで ` FormsModule ` をオプトインします。
182193
183- ### Import _ FormsModule_
194+ {@a import-formsmodule}
195+ ### _ FormsModule_ をインポートする
184196
185- Open ` AppModule ` (` app.module.ts ` ) and import the ` FormsModule ` symbol from the ` @angular/forms ` library.
197+ ` AppModule ` (` app.module.ts ` ) を開き、 ` @angular/forms ` ライブラリから ` FormsModule ` シンボルをインポートします。
186198
187- <code-example path="toh-pt1/src/app/app.module.ts" title="app.module.ts (FormsModule symbol import )"
199+ <code-example path="toh-pt1/src/app/app.module.ts" title="app.module.ts (FormsModule シンボルのインポート )"
188200 region="formsmodule-js-import">
189201</code-example >
190202
191- Then add ` FormsModule ` to the ` @NgModule ` metadata's ` imports ` array, which contains a list of external modules that the app needs.
203+ それから、` FormsModule ` を` @NgModule ` メタデータの` imports ` 配列に追加します。
204+ この配列には、アプリケーションに必要な外部モジュールのリストが含まれています。
192205
193206<code-example path="toh-pt1/src/app/app.module.ts" title="app.module.ts ( @NgModule imports)"
194207region="ng-imports">
195208</code-example >
196209
197- When the browser refreshes, the app should work again. You can edit the hero's name and see the changes reflected immediately in the ` <h2> ` above the textbox.
210+ ブラウザが更新されると、アプリケーションは再び動作するはずです。ヒーローの名前を編集し、テキストボックスの上にある ` <h2> ` に即座に変更が反映されていることを確認できます。
198211
199- ### Declare _ HeroesComponent_
212+ {@a declare-heroescomponent}
213+ ### _ HeroesComponent_ を宣言する
200214
201- Every component must be declared in _ exactly one _ [ NgModule] ( guide/ngmodule ) .
215+ すべてのコンポーネントは、 _ ただ1つの _ [ NgModule] ( guide/ngmodule ) で宣言されなければなりません。
202216
203- _ You _ didn't declare the ` HeroesComponent ` .
204- So why did the application work?
217+ _ あなたは _ ` HeroesComponent ` を宣言していません。
218+ では、なぜアプリケーションは動作したのでしょうか?
205219
206- It worked because the Angular CLI declared ` HeroesComponent ` in the ` AppModule ` when it generated that component.
220+ アプリケーションが動作したのは、 Angular CLI が ` HeroesComponent ` を生成したときに、 ` AppModule ` でそのコンポーネントの宣言を行っていたからです。
207221
208- Open ` src/app/app.module.ts ` and find ` HeroesComponent ` imported near the top.
222+ ` src/app/app.module.ts ` を開き、先頭付近で ` HeroesComponent ` がインポートされているのを見つけてください。
209223<code-example path =" toh-pt1/src/app/app.module.ts " region =" heroes-import " >
210224</code-example >
211225
212- The ` HeroesComponent ` is declared in the ` @NgModule.declarations ` array.
226+ ` HeroesComponent ` は、 ` @NgModule.declarations ` 配列で宣言されています。
213227<code-example path =" toh-pt1/src/app/app.module.ts " region =" declarations " >
214228</code-example >
215229
216- Note that ` AppModule ` declares both application components, ` AppComponent ` and ` HeroesComponent ` .
230+ ` AppModule ` は ` AppComponent ` と ` HeroesComponent ` の両方のアプリケーションコンポーネントを宣言しています。
217231
218232
219- ## Final code review
233+ {@a final-code-review}
234+ ## 最終的なコードレビュー
220235
221- Your app should look like this <live-example ></live-example >. Here are the code files discussed on this page.
236+ あなたのアプリケーションはこのように見えるはずです <live-example ></live-example > 。このページで解説したコードファイルは次のとおりです。
222237
223238<code-tabs >
224239
@@ -244,13 +259,13 @@ Your app should look like this <live-example></live-example>. Here are the code
244259
245260</code-tabs >
246261
247- ## Summary
262+ {@a summary}
263+ ## まとめ
248264
249- * You used the CLI to create a second ` HeroesComponent ` .
250- * You displayed the ` HeroesComponent ` by adding it to the ` AppComponent ` shell.
251- * You applied the ` UppercasePipe ` to format the name.
252- * You used two-way data binding with the ` ngModel ` directive.
253- * You learned about the ` AppModule ` .
254- * You imported the ` FormsModule ` in the ` AppModule ` so that Angular would recognize and apply the ` ngModel ` directive.
255- * You learned the importance of declaring components in the ` AppModule `
256- and appreciated that the CLI declared it for you.
265+ * CLIを使用して、2番目の ` HeroesComponent ` を作成しました。
266+ * ` HeroesComponent ` を ` AppComponent ` シェルに追加して表示しました。
267+ * 名前をフォーマットするために、 ` UppercasePipe ` を適用しました。
268+ * ` ngModel ` ディレクティブで双方向データバインディングを使用しました。
269+ * ` AppModule ` について学びました。
270+ * ` AppModule ` に ` FormsModule ` をインポートして、Angular ` ngModel ` ディレクティブを認識して適用するようにしました。
271+ * ` AppModule ` でコンポーネントを宣言することの重要性を学び、CLIがあなたのためにその宣言を行っていることを認識しました。
0 commit comments