角度2:找不到名称"Subscription" [英] Angular 2: Cannot find name 'Subscription'
本文介绍了角度2:找不到名称"Subscription"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
尝试设置属性类型时,出现错误找不到名称'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.
@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();
}
}
编辑:提供更详细的代码示例.
Provide a more detailed code example.
推荐答案
您必须像这样导入它:
import { Subscription } from 'rxjs';
原始答案
import { Subscription } from 'rxjs/Subscription';
在这里看看: https://angular.io/docs/ts/latest/guide/router.html 并且在该文档中有几个punker的链接.
Take a look here: https://angular.io/docs/ts/latest/guide/router.html and there are several plunker's linked in that documentation.
这篇关于角度2:找不到名称"Subscription"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文