本文整理匯總了TypeScript中rxjs/observable/fromEvent.fromEvent函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript fromEvent函數的具體用法?TypeScript fromEvent怎麽用?TypeScript fromEvent使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了fromEvent函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: constructor
constructor(private sanitizer: DomSanitizer, private orientation: ScreenOrientation) {
this.fullscreen = merge(
fromEvent(document, 'fullscreenchange'),
fromEvent(document, 'webkitfullscreenchange'),
fromEvent(document, 'mozfullscreenchange'),
);
}
示例2: dragOver
private dragOver() {
const dragEnter = fromEvent(this.el, this.domEvents.ON_DRAG_ENTER_EVENT);
const dragLeave = fromEvent(this.el, this.domEvents.ON_DRAG_LEAVE_EVENT);
return dragEnter.pipe(
flatMap(mouseDrag => of(mouseDrag).pipe(
delay(500),
takeUntil(dragLeave)
))
);
}
示例3: switchMap
switchMap(scroll => {
if (!scroll) return empty();
return fromEvent(document, "scroll", true).pipe(
map((e: Event) => e.target),
withLatestFrom(canSync$, elemMap$),
filter(([, canSync]) => Boolean(canSync)),
map(([target, canSync, elemMap]: [any, boolean, any[]]) => {
if (target === document) {
return ScrollEvent.outgoing(
getScrollPosition(window, document),
"document",
0
);
}
const elems = document.getElementsByTagName(target.tagName);
const index = Array.prototype.indexOf.call(
elems || [],
target
);
return ScrollEvent.outgoing(
getScrollPositionForElement(target),
target.tagName,
index,
elemMap.indexOf(target)
);
})
);
})
示例4: hookToButtonKeyPressAndSubscribeToEvents
hookToButtonKeyPressAndSubscribeToEvents() {
const inputElement = document.getElementById('inputstuff');
const keyPress$ = fromEvent<ElementRef>(inputElement, 'keypress')
.pipe(delay(500));
keyPress$.subscribe(
(keypressevent: any) => {
this.inputdata = (this.inputdata ? this.inputdata : '') + keypressevent.key;
}
);
}
示例5: showAt
showAt(container: ViewContainerRef, menuItems: MenuItem[], coordinates: { x: number, y: number }) {
this.close();
const factory = this.resolver.resolveComponentFactory(MenuComponent);
this.embeddedComponent = container.createComponent<MenuComponent>(factory);
this.embeddedComponent.instance.setItems(menuItems);
const nEl = this.embeddedComponent.location.nativeElement as HTMLElement;
const {x, y} = coordinates;
nEl.style.position = "fixed";
nEl.style.left = x + "px";
nEl.style.top = y + "px";
fromEvent(nEl, "contextmenu").subscribe((ev: MouseEvent) => {
ev.stopPropagation();
});
fromEvent(document, "click").pipe(
take(1)
).subscribe(() => {
this.close();
});
}
示例6: switchMap
switchMap(canToggle => {
if (!canToggle) {
return empty();
}
return fromEvent(document, "change", true).pipe(
map((e: Event) => e.target || e.srcElement),
filter((elem: HTMLInputElement) => elem.tagName === "SELECT"),
withLatestFrom(canSync$),
filter(([, canSync]) => canSync),
map(([elem, canSync]: [HTMLInputElement, boolean]) => {
const data = getElementData(elem);
return FormToggleEvent.outgoing(data, {
type: elem.type,
checked: elem.checked,
value: elem.value
});
})
);
})
示例7: switchMap
switchMap(formInputs => {
if (!formInputs) {
return empty();
}
return fromEvent(document.body, "keyup", true).pipe(
map((e: Event) => e.target || e.srcElement),
filter(
(target: Element) =>
target.tagName === "INPUT" ||
target.tagName === "TEXTAREA"
),
withLatestFrom(canSync$),
filter(([, canSync]) => canSync),
map(([eventTarget]) => {
const target = getElementData(eventTarget);
const value = eventTarget.value;
return KeyupEvent.outgoing(target, value);
})
);
})
示例8: switchMap
switchMap(canClick => {
if (!canClick) {
return empty();
}
return fromEvent(document, "click", true).pipe(
map((e: Event) => e.target),
filter((target: any) => {
if (target.tagName === "LABEL") {
const id = target.getAttribute("for");
if (id && document.getElementById(id)) {
return false;
}
}
return true;
}),
withLatestFrom(canSync$),
filter(([, canSync]) => canSync),
map(([target]): OutgoingSocketEvent => {
return ClickEvent.outgoing(getElementData(target));
})
);
})
示例9: fromEvent
this._change = platform.isBrowser ? ngZone.runOutsideAngular(() => {
return merge<Event>(fromEvent(window, 'resize'), fromEvent(window, 'orientationchange'));
}) : observableOf();
示例10: fromEvent
import { fromEvent } from 'rxjs/observable/fromEvent';
import { ajax } from 'rxjs/observable/dom/ajax';
import { map, filter, debounceTime, distinctUntilChanged, switchMap } from 'rxjs/operators';
const searchBox = document.getElementById('search-box');
const typeahead = fromEvent(searchBox, 'input').pipe(
map((e: KeyboardEvent) => e.target.value),
filter(text => text.length > 2),
debounceTime(10),
distinctUntilChanged(),
switchMap(() => ajax('/api/endpoint'))
);
typeahead.subscribe(data => {
// Handle the data from the API
});