小编sch*_*ire的帖子

订阅中的 Angular 订阅

我有以下代码,其中包含多个订阅。我需要实现的是这样的:

  1. 订阅 activateRoute 以获取用户和产品数据。
  2. 返回商品数据后,使用商品数据订阅getSeller服务。
  3. 使用返回的卖家数据订阅 getRating 服务。

我的问题:有没有更好的方法来执行这些嵌套订阅?这样做是一个好习惯吗?

this.activatedRoute.data.pipe(
 map((data) => {
    this.user = data['user'];
    this.product = data['product'];

    return this.product;
  })
).subscribe(result => {

  if (this.product === null) {
    this.router.navigate(['/home']);
  } else {
    this.displayCurrency = this.dataService.getCurrencySymbolById(this.product.currency);

    this.userService.getUser(this.product.createdBy).subscribe(seller => {
      this.seller = seller;

      this.ratingService.getRatingByUserId(seller.id).subscribe(rating => {
        this.rating = rating;
      })

    });
  }
});
Run Code Online (Sandbox Code Playgroud)

rxjs angular

9
推荐指数
1
解决办法
1万
查看次数

Fullcalendar onclick show dayview

我是Javascript的新手,特别是在JSON和Jquery上.我已经成功实现了FullCalendar的月度视图,但是无论如何根据用户点击月视图的日期显示或弹出日视图?任何帮助将非常感激

onclick days fullcalendar

4
推荐指数
1
解决办法
6224
查看次数

Angular 将数组转换为字符串

我有以下数组 (testArray),我希望将所有州提取到字符串中 ('Arizona','Alaska','Florida','Hawaii','Gujarat','Goa','Punjab'...) . 有没有更简单的方法来做到这一点?

let testArray: State[];
testArray = this.getStates();

getStates() {
 return [
  new State(1, 1, 'Arizona'),
  new State(2, 1, 'Alaska'),
  new State(3, 1, 'Florida'),
  new State(4, 1, 'Hawaii'),
  new State(5, 2, 'Gujarat'),
  new State(6, 2, 'Goa'),
  new State(7, 2, 'Punjab'),
  new State(8, 3, 'Queensland'),
  new State(9, 3, 'South Australia'),
  new State(10, 3, 'Tasmania'),
  new State(11, 4, 'Penang')
 ];
}
Run Code Online (Sandbox Code Playgroud)

javascript arrays angular

4
推荐指数
2
解决办法
2万
查看次数

标签 统计

angular ×2

arrays ×1

days ×1

fullcalendar ×1

javascript ×1

onclick ×1

rxjs ×1