属性のタイプを設定しようとすると、エラーCannot find name 'Subscription'
が発生します。どのパッケージからインポートしますか?角2:名前「サブスクリプション」を見つけることができません
import { Component, OnDestroy, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
// I'm missing an import here. Just don't know which package to load from.
@Component({
moduleId: module.id,
selector: 'my-component',
templateUrl: 'my.component.html',
styleUrls: ['my.component.css']
})
export class MyComponent implements OnInit, OnDestroy {
private sub: any;
constructor(private route: ActivatedRoute,
private router: Router) {}
ngOnInit() {
this.sub = this.route.params.subscribe(params => {
let id = +params['id']; // (+) converts string 'id' to a number
});
}
ngOnDestroy() {
this.sub.unsubscribe();
}
}
編集:より詳細なコード例を提供します。
を、あなたは、いくつかのより多くのコードと詳細 – rashfmnb
を投稿することができます私は、次のよ角度2の文書。彼らはしばしばユーザーが研究しなければならない重要な情報を残し、多くの時間を無駄にします。これはかなり面倒です。これが役に立ったら、サンプルコンポーネントを書くことができます。私に秒をください。 –
@rashfmnb:完了。既に解決策があります。ありがとう。 –