eventemitter

Subscribe to EventEmitter in Angular2 not working

夙愿已清 提交于 2019-12-21 05:39:10
问题 I'm learning Angular 2. I'm trying to send data from a component to other on the click of the first one. Both components are siblings. This is my code so far: First Component: @Component({ selector: 'jsonTextInput', templateUrl: '../templates/jsonTextInput.html', directives: [Card, CardTitle, CardDescription, Icon], providers: [JsonChangeService] }) export class JsonTextInput { json: string = ''; constructor (private jsonChangeService: JsonChangeService) { this.jsonChangeService =

angular 2: using a service to broadcast an event

跟風遠走 提交于 2019-12-20 08:59:53
问题 I'm trying to get a button click in one component to put focus on an element on another component. (Frankly, I don't understand why this must be so complex, but I have not been able to implement any simpler way that actually works.) I'm using a service. It doesn't need to pass any data except that the click occurred. I'm not sure how the listening component is meant to respond to the event. app.component: Skip to main content import { Component } from '@angular/core'; import {

Node.js EventEmitter error

戏子无情 提交于 2019-12-20 05:39:15
问题 I have an error when trying to inherit EvenEmitter /* Consumer.js */ var EventEmitter = require('events').EventEmitter; var util = require('util'); var Consumer = function() {}; Consumer.prototype = { // ... functions ... findById: function(id) { this.emit('done', this); } }; util.inherits(Consumer, EventEmitter); module.exports = Consumer; /* index.js */ var consumer = new Consumer(); consumer.on('done', function(result) { console.log(result); }).findById("50ac3d1281abba5454000001"); /*

Node.js event-stream: Where to setMaxListeners?

佐手、 提交于 2019-12-20 04:31:09
问题 I have searched and searched for this, to no avail. I've combed the web (including Stackoverflow), and the Node docs for an answer, and not found one---that worked (maybe that's just bad searching on my part). I'm working with an event-stream in a gulp config file, and I have a particular task that is hitting the classic "memory leak detected" error from the EventEmitter class. From what I've found, the answer to dealing with this issue seems to be to call the setMaxListeners method of the

Node.js event-stream: Where to setMaxListeners?

一世执手 提交于 2019-12-20 04:31:08
问题 I have searched and searched for this, to no avail. I've combed the web (including Stackoverflow), and the Node docs for an answer, and not found one---that worked (maybe that's just bad searching on my part). I'm working with an event-stream in a gulp config file, and I have a particular task that is hitting the classic "memory leak detected" error from the EventEmitter class. From what I've found, the answer to dealing with this issue seems to be to call the setMaxListeners method of the

How do you share an EventEmitter in node.js?

霸气de小男生 提交于 2019-12-18 12:49:16
问题 I want to emit events from one file/module/script and listen to them in another file/module/script. How can I share the emitter variable between them without polluting the global namespace? Thanks! 回答1: You can pass arguments to require calls thusly: var myModule = require('myModule')(Events) And then in "myModule" module.exports = function(Events) { // Set up Event listeners here } With that said, if you want to share an event emitter, create an emitter object and then pass to your "file

Angular2, unsubsribe from event in ngOnDestroy [duplicate]

江枫思渺然 提交于 2019-12-18 12:47:32
问题 This question already has answers here : How to cancel a subscription in Angular2 (8 answers) Closed 2 years ago . In my application I have some components that communicate by means of EventService . @Injectable() export class EventService { public myEvent: EventEmitter<any> = new EventEmitter(); constructor() {} } This service is injected in a EmitterComponent that emits the event when a button is clicked @Component({ selector: 'emitter', template: `<button (click)="onClick()">Click me<

How pass 2 parameters to EventEmitter angular2

五迷三道 提交于 2019-12-18 11:37:45
问题 I have in my component a EventEmitter but I can't compile because return this error: "Supplied parameters do not match any signature of call target" My component: @Output() addModel = new EventEmitter<any>(); saveModel($event, make, name) { this.addModel.emit(make, name); } If i delete one of parameters in this.addModel.emit() it work, but so, Can i pass 2 parameters and how, to my eventEmitter? I tried also with : @Output() addModel = new EventEmitter<any,any>(); but It doesn't work 回答1: If

Waiting for an Asynchronous method in NodeJS

匆匆过客 提交于 2019-12-13 13:14:30
问题 I've looked high and low, and can only find how to write async functions, which I already understand. What I am trying to do is run an async method in a triggered event [EventEmitter], but such a simple thing seems to be just simply not possible as I can find. Consider the following... // Your basic async method.. function doSomething(callback) { var obj = { title: 'hello' }; // Fire an event for event handlers to alter the object. // EvenEmitters are called synchronously eventobj.emit('alter

Accessing an object's parent (or instance?) given a sub-object [duplicate]

强颜欢笑 提交于 2019-12-13 10:25:30
问题 This question already has answers here : Javascript objects: get parent [duplicate] (12 answers) Closed 2 years ago . I have an object variable a, which has an array associated with it, b. I am passing b to a function and need to check properties in a, the object it's associated with. How can I do this? Can I somehow use an event emitter? function ObjectB (stuff) { this.a = new a(); } function doSomething (s) { //need to get b from a } var b = new ObjectB(info); b.a.doSomething(5); 回答1: There