Øle Bjarnstroem Øle Bjarnstroem - 1 year ago 154
TypeScript Question

Angular 2: Cannot find name 'Subscription'

When trying to set the type of an attribute I get the error

Cannot find name 'Subscription'
. From which package do I import it from?

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.

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() {


Edit: Provide a more detailed code example.

Answer Source

You have to import it like this: import { Subscription } from 'rxjs/Subscription';

Take a look here: https://angular.io/docs/ts/latest/guide/router.html and there are several plunker's linked in that documentation.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download