import { Component, Input, Output, EventEmitter } from '@angular/core';
var colorPickerCss = "app/css/ui/color-picker.css";
var colorPickerTemplate = "app/partials/color-picker.html";
@Component({
selector: 'color-picker',
styleUrls: [colorPickerCss],
templateUrl: colorPickerTemplate
})
export class ColorPicker{
@Input() colors: string[] = [];
@Output() selectedColor = new EventEmitter();
isSelectorVisible : boolean = false;
showSelector(value: boolean){
this.isSelectorVisible = value;
}
selectColor(color: string){
this.showSelector(false);
this.selectedColor.next({color});
}
} ;
I have written the above code, but I want to understand the functioning of it. My question is, what is the .next() function on this line this.selectedColor.next({color}). What library is it from? I have mentioned the imports above, but I can't really get to the actual definition of this function.
import { Component, Input, Output, EventEmitter } from '@angular/core';
var colorPickerCss = "app/css/ui/color-picker.css";
var colorPickerTemplate = "app/partials/color-picker.html";
@Component({
selector: 'color-picker',
styleUrls: [colorPickerCss],
templateUrl: colorPickerTemplate
})
export class ColorPicker{
@Input() colors: string[] = [];
@Output() selectedColor = new EventEmitter();
isSelectorVisible : boolean = false;
showSelector(value: boolean){
this.isSelectorVisible = value;
}
selectColor(color: string){
this.showSelector(false);
this.selectedColor.next({color});
}
} ;
I have written the above code, but I want to understand the functioning of it. My question is, what is the .next() function on this line this.selectedColor.next({color}). What library is it from? I have mentioned the imports above, but I can't really get to the actual definition of this function.
Share Improve this question edited Jul 29, 2017 at 20:41 alexmac 19.6k7 gold badges64 silver badges74 bronze badges asked Jul 29, 2017 at 20:24 user4284057user4284057 1- 2 next is deprecated - see this question and the answer there also mentions this resource if that helps in your understanding – 0mpurdy Commented Jul 29, 2017 at 20:31
1 Answer
Reset to default 8An EventEmitter, extends Subject. When you use next, you fire off an event that all subscribers will listen too. See here. emit is the preferred alternative.