异步管道的可观察问题

时间:2016-07-28 16:09:48

标签: angularjs angular observable observablelist reactivex

我正在使用library来帮助我通过拖放对列表进行排序。

并且我给它的列表是列表类型的Observable,然后我使用async在html中读取它,它非常简单,看起来像这样:

@Injectable()
export class MyCmp implements OnInit {

  myList: Observable<MyListType[]>;

  showingList = false;

  constructor(private _myService: MyService) {
  };


  public showListData(): void {
    this.showingList = true;
    this.myList = this._myService.getListData();
  }
}

这是html:

  <button md-button
          (click)="showListData()"
          title="">Show List
  </button>

</div>


<md-content>

  <div *ngIf="showingList">
    <div dnd-sortable-container [sortableData]="myList | async">
      <div class="list-bg" *ngFor="#item of myList | async; #i = index" dnd-sortable [sortableIndex]="i">
        ID: {{item.id}} <p></p> Name: {{item.name}}
      </div>
    </div>
    <div>Current List {{myList | async | json}}</div>
  </div>

</md-content>

现在这不起作用,但是,如果我在我的组件中执行此操作而不是myList: Observable<MyListType[]>;

我做:

  myList  = this._myService.getListData();

然后在html传递myList中它很有用......

我不明白!!让我抓狂:/

请帮助

getListData()喜欢这样:

public getListData(): Observable<MyListType[]> {
    return this._someApiService.getCurrentListData().map(res => res.info);
  }

0 个答案:

没有答案
相关问题