.next()函数的角度说明 [英] Explanation for the .next() function in angular

查看:80
本文介绍了.next()函数的角度说明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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});
    }


} ;

我已经编写了上面的代码,但是我想了解它的功能.我的问题是, this.selectedColor.next({color})这行上的.next()函数是什么.它来自哪个图书馆?我已经在上面提到了导入,但是我无法真正了解此函数的实际定义.

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.

推荐答案

EventEmitter 进行了扩展学科.当您使用next时,您将触发一个事件,所有订阅者也将收听.请参见此处.发出是首选.

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.

这篇关于.next()函数的角度说明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆