eventemitter

Angular2 - 'watch' provider property in multiple components

天涯浪子 提交于 2019-12-10 13:46:33
问题 I'm coming form NG1 environment and currently I'm creating NG2 app with all available features. Before asking I was exploring google and stackoverflow questions but with no luck since angular 2 moved so fast with api architecture and most answers are out of date. My case: I have Auth provider (service) with property user, I would like to observe user and react in multiple components (navbar, sidebar etc.) What I tried: @Injectable(); export class Auth { private user; authorized: EventEmitter

How to unsubscribe from EventEmitter in Angular 2?

爷,独闯天下 提交于 2019-12-09 00:28:51
问题 export declare class EventEmitter<T> extends Subject<T> { /** * Creates an instance of [EventEmitter], which depending on [isAsync], * delivers events synchronously or asynchronously. */ constructor(isAsync?: boolean); emit(value: T): void; /** * @deprecated - use .emit(value) instead */ next(value: any): void; subscribe(generatorOrNext?: any, error?: any, complete?: any): any; } In Official Angular 2 Typescript definition, seems it has no way to mute or unsubscribe from EventEmitter. I got

node.js eventEmitter : Listen for events across files

情到浓时终转凉″ 提交于 2019-12-08 08:04:20
问题 Just getting started on Node.js, I have the following query: I have a following javascript in my server.js file: ==================================================== function onRequest(request, response) { var pathname = url.parse(request.url).pathname; route(handle, pathname, response); console.log("Request for " + pathname + " received."); } var server = http.createServer(onRequest) server.listen(8888); console.log("Server started") ==========================================================

how to access this inside an event receiver angular

会有一股神秘感。 提交于 2019-12-08 03:45:06
问题 I was going over this tutorial to implement sending/receiving broadcast messages in my angular 1.5 app. so inside a controller I have this: update(){ this.$rootScope.$broadcast('language_changed'); } and in another controller I got this: $rootScope.$on('language_changed', function (event, data){ this.updateStore(); <--- this here is undefined }); } updateStore() { this.store = { .. language_id: this.LanguageService.get(), } } I'm wondering how can I get hold of this inside the broadcast. This

node.js eventEmitter : Listen for events across files

空扰寡人 提交于 2019-12-07 18:03:26
Just getting started on Node.js, I have the following query: I have a following javascript in my server.js file: ==================================================== function onRequest(request, response) { var pathname = url.parse(request.url).pathname; route(handle, pathname, response); console.log("Request for " + pathname + " received."); } var server = http.createServer(onRequest) server.listen(8888); console.log("Server started") =============================================================== I have another js file, where I want to register a listener for the "listening" event emitted by

How to make an EventEmitter listen to another EventEmitter in Node.js?

送分小仙女□ 提交于 2019-12-07 09:31:57
问题 I want to do something like this: var events = require("events"); var emitterA = new events.EventEmitter(); var emitterB = new events.EventEmitter(); emitterA.addListener("testA", function(){ console.log("emitterA detected testA"); }); emitterB.addListener("testA", function(){ console.log("emitterB detected testA"); }); emitterA.emit("testA"); And the output to be this: emitterA detected testA emitterB detected testA But when I run this code, the output I get is: emitterA detected testA I

Angular 4 emitting and subscribing to an event in a shared service

廉价感情. 提交于 2019-12-07 05:23:43
问题 I am emitting an event in my main component: main.component.ts this.sharedService.cartData.emit(this.data); Here is my sharedService.ts import { Component, Injectable, EventEmitter } from '@angular/core'; export class SharedService { cartData = new EventEmitter<any>(); } In my other (Sub) Component, I want to access this value, but somehow, the subscription does not work: dashboard.ts private myData: any; constructor(private sharedService: SharedService) { this.sharedService.cartData

How to document an event emitter returned

╄→гoц情女王★ 提交于 2019-12-07 04:00:36
问题 How to document the events emitted by stream returned in MyFunc() with JSDoc? /** * [MyFunc description] * @param {Object} opts - [description] * @return {Stream} - [description] */ function MyFunc (opts) { // stream is an EventEmitter var stream = new MyEventEmitter(); stream.emit('event1', ... ); stream.emit('event2', ... ); return stream; } 回答1: You can document these behaviors by documenting your events ( event1 , event2 , ...) as @event MyFunc#event1 and MyFunc, or whoever does the

Use EventEmitter in ES6 class

与世无争的帅哥 提交于 2019-12-06 17:00:41
问题 I am trying to get the EventEmitter in my own class running in ES6: "use strict"; const EventEmitter = require('events'); class Client extends EventEmitter{ constructor(token, client_id, client_secret, redirect_uri, code){ super(); this.token = token; this.client_id = client_id; this.client_secret = client_secret; this.redirect_uri = redirect_uri; this.code = code; } eventTest(){ this.emit("event"); console.log(this.token); } } let testClient = new Client(1,2,3,4,5); testClient.eventTest();

Emit and broadcast events throughout application in Angular

我的梦境 提交于 2019-12-06 13:20:55
Is there a way to emit event in angular2 that can be listened to in entire application? Like we had in AngularJS using $rootScope.broadcast and emit . Can this same thing be achieved in angular2? I read about @Output() and EventEmitter() and implemented it but it restricts only the parent to listen to the event emmitted by child. I read about BehaviorSubject being one of the ways to do this. Is that the right approach? Any other solution for this? Günter Zöchbauer In Angular2 there is no global scope. There are only components and services. With services you can define their scope by the place