最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Explanation for the .next() function in angular - Stack Overflow

programmeradmin1浏览0评论
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
Add a ment  | 

1 Answer 1

Reset to default 8

An 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.

发布评论

评论列表(0)

  1. 暂无评论