When I attempt to define the type of an attribute, I encounter the error Cannot find name 'Subscription'
. Where should I import it from?
import { Component, OnDestroy, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
// There seems to be a missing import here. I'm unsure which package it should be loaded 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();
}
}
Edit: Can you provide a more in-depth code example?