我有以下内容:
angular2 (NameCmp)
import {
OnInit, Component, ChangeDetectionStrategy, ViewChild, ElementRef,
AfterViewInit
} from 'angular2/core'
import {Observable} from 'rxjs/Observable';
..
export class NameCmp implements AfterViewInit{
....
@ViewChild('card')
card: ElementRef;
mouseMoves$: Observable<MouseEvent>;
ngAfterViewInit(): void {
this.mouseMoves$ = Observable.fromEvent(this.card.nativeElement, 'mousemove');
this.mouseMoves$.subscribe( event => console.log('logging mousemove'));
console.log('after view init')
}
.html
...
<md-card #card>
<md-card-content>
<md-input
required
placeholder = "Title"
[ngFormControl] = "titleCtrl"></md-input>
</md-card-content>
</md-card>
但是,虽然console.log('after view init')
打印到控制台,但console.log('logging mousemove'));
语句不会。
谢谢