小编Ser*_*hon的帖子

Angular/RxJs什么时候应该取消订阅"订阅"

我应该何时存储Subscription实例并unsubscribe()在NgOnDestroy生命周期中调用,何时可以忽略它们?

保存所有订阅会在组件代码中引入很多混乱.

HTTP客户端指南忽略这样的订阅:

getHeroes() {
  this.heroService.getHeroes()
                   .subscribe(
                     heroes => this.heroes = heroes,
                     error =>  this.errorMessage = <any>error);
}
Run Code Online (Sandbox Code Playgroud)

同时," 航线与导航指南"说:

最终,我们会在其他地方导航.路由器将从DOM中删除此组件并将其销毁.在此之前我们需要自己清理.具体来说,我们必须在Angular破坏组件之前取消订阅.如果不这样做可能会造成内存泄漏.

我们取消订阅我们ObservablengOnDestroy方法.

private sub: any;

ngOnInit() {
  this.sub = this.route.params.subscribe(params => {
     let id = +params['id']; // (+) converts string 'id' to a number
     this.service.getHero(id).then(hero => this.hero = hero);
   });
}

ngOnDestroy() {
  this.sub.unsubscribe();
}
Run Code Online (Sandbox Code Playgroud)

subscription observable rxjs angular angular-component-life-cycle

653
推荐指数
10
解决办法
15万
查看次数

Suave in watch模式(开发期间)

我正在研究Suave 1.0 + Angular 2.0示例应用程序并且在监视模式下启动Suave服务器非常有趣,因此服务器监视文件在根文件夹和子文件夹中更改(js,css,html)并自动向refresh所有打开的浏览器发送命令任何文件更改时,我的应用程序的选项卡.

lite-server来自Angular 2 5min Quckstark可以做到这一点,它非常方便.

我认为大多数表款都可以在最新的Steffen Forkmann的帖子中找到,但是如何发送refresh到开放的浏览器标签并不是很干净.

请提供类似实现的完整代码Suave.

f# suave

8
推荐指数
1
解决办法
625
查看次数

F#Type Provider编译为*.exe文件

为什么我无法使用[<TypeProviderAssembly()>][<EntryPoint>]内部创建Type Provider作为*.exe文件?

当我尝试引用这样的TP时#r @"d:\TP\bin\Debug\MyTypeProvider.exe",我看到以下内容:

test.fsx(3,1): error FS3031: The type provider 'd:\TP\bin\Debug\MyTypeProvider.exe' reported an error: Assembly attribute 'TypeProviderAssemblyAttribute' refers to a designer assembly 'MyTypeProvider' which cannot be loaded or doesn't exist. Could not load file or assembly 'file:///d:\TP\bin\Debug\MyTypeProvider.dll' or one of its dependencies. The system cannot find the file specified.

我需要在单独的进程中有一个类型推断运行时,因为它应该是64bit(与32bitVS进程不同).但我希望将所有内容打包到一个文件中,从VS引用它并从外部进程开始.

f# type-providers

6
推荐指数
1
解决办法
237
查看次数