小编Qua*_*ali的帖子

获取字符串文字类型值的数组

我需要获取字符串文字的所有可能值的完整列表.

type YesNo = "Yes" | "No";
let arrayOfYesNo : Array<string> = someMagicFunction(YesNo); //["Yes", "No"]
Run Code Online (Sandbox Code Playgroud)

有没有办法实现这个?

typescript

15
推荐指数
2
解决办法
7729
查看次数

Anuglar2生命周期事件为rxjs Observable

是否有一种构建方式来获得像OnDestroyrxjs 一样的angular2生命周期事件Observable

我想订阅这样的观察:

ngOnInit() {
  MyService.myCustomFunction()
    .takeUntil(NgOnDestroy)  //NgOnDestroy would be the lifecycle observable
    .subscribe(() => {
      //any code
    });
 }
Run Code Online (Sandbox Code Playgroud)

这似乎更直观,更好阅读:

private customObservable: Observable;

ngOnDestroy() {
  this.customObservable.unsubscribe();
}

ngOnInit() {
  this.customObservable = MyService.myCustomFunction()
    .subscribe(() => {
      //any code
    });
 }
Run Code Online (Sandbox Code Playgroud)

javascript observable rxjs angular

11
推荐指数
1
解决办法
1053
查看次数

标签 统计

angular ×1

javascript ×1

observable ×1

rxjs ×1

typescript ×1