当试图设置属性的类型时,我得到了错误Cannot find name 'Subscription'.我应该从哪个包裹导入?

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();
  }

}

Edit:提供了一个更详细的代码示例.

推荐答案

您必须这样导入它:

import { Subscription } from 'rxjs';

ORIGINAL ANSWER

import { Subscription } from 'rxjs/Subscription';

看看这里:https://angular.io/docs/ts/latest/guide/router.html

Typescript相关问答推荐

Angular -使用Phone Directive将值粘贴到控件以格式化值时验证器不工作

使用FormArray在Angular中添加排序

动态判断TypScript对象是否具有不带自定义类型保护的键

类型脚本类型字段组合

具有泛型类型和缺省值的键

如何按不能保证的功能过滤按键?

在TypeScrip的数组中判断模式类型

为什么我的一个合成函数不能推断类型?

有没有办法取消分发元组的联合?

将带有样式的Reaction组件导入到Pages文件夹时不起作用

从route.参数获取值.订阅提供";无法读取未定义";的属性

类型推断对React.ForwardRef()的引用参数无效

17个Angular 的延迟观察.如何在模板中转义@符号?

如何连接属性名称和值?

顶点堆叠的图表条形图未在正确的x轴上显示

有没有一种更好的方法来存储内存中的数据,而不是在类型脚本中使用数组和基于索引的函数?

递归类型别名的Typescript 使用

内联类型断言的工作原理类似于TypeScrip中的断言函数?

两个子组件共享控制权

广义泛型类型不加载抽象类型上下文