相关疑难解决方法(0)

"async"管道不呈现流更新

尝试在窗口上渲染窗口大小,通过使用async管道的角度2组件中的流调整大小:

<h2>Size: {{size$ | async | json}}</h2>

const windowSize$ = new BehaviorSubject(getWindowSize());
Observable.fromEvent(window, 'resize')
  .map(getWindowSize)
  .subscribe(windowSize$);

function getWindowSize() {
  return {
    height: window.innerHeight,
    width: window.innerWidth
  };
}

@Component({
  selector: 'my-app',
  providers: [],
  template: `
    <div>
      <h2>Size: {{size$ | async | json}}</h2>
    </div>
  `,
  directives: []
})
export class App {
  size$ = windowSize$.do(o => console.log('size:', o));
  constructor() {  }
}
Run Code Online (Sandbox Code Playgroud)

但该组件仅呈现初始状态并忽略流更新.如果您打开控制台,在窗口调整大小时,您将看到来自同一个流的更新.

无法理解我在这里缺少什么.

这是一个吸烟者

rxjs rxjs5 angular2-changedetection angular

13
推荐指数
2
解决办法
8533
查看次数

标签 统计

angular ×1

angular2-changedetection ×1

rxjs ×1

rxjs5 ×1