Angularのチュートリアルでの勉強は昨日やったところまでで終わりにしようと思っていたのですが、その続きの部分をちょこちょこと見ていたら、ちょっと気づいたことがあります。
Angular公式の日本語版と英語版の違い
ナビゲーションの追加というドキュメントのngOnInit()メソッドのコードです。
product-details.component.ts
ngOnInit() {
this.route.paramMap.subscribe(params => {
this.product = products[+params.get('productId')];
});
}
英語版では下記のようになっていますね。
product-details.component.ts
ngOnInit() {
// First get the product id from the current route.
const routeParams = this.route.snapshot.paramMap;
const productIdFromRoute = Number(routeParams.get('productId'));
// Find the product that correspond with the id provided in route.
this.product = products.find(product => product.id === productIdFromRoute);
}
(日本語版はきっとボランティア的に翻訳して下さっている方々がいらっしゃるのかなと思います。)
もちろん英語版が本家ですから、英語版の方が新しい情報かとは思います。
(プログラミングって、バージョンの違いか環境の違いでプログラムの書き方によってコンパイルエラーになることがありますね。)