繁体   English   中英

Angular2错误:导出类的公共方法的返回类型具有或正在使用私有名称

[英]Angular2 Error: Return type of public method from exported class has or is using private name

在最初使用非CLI版本的Angular 2构建应用程序的工作版本之后,我正在使用Angular-CLI构建Angular 2应用程序。令我惊讶的是,某些代码在我的非CLI中不是问题应用程序版本已成为我的Angular-CLI版本的问题。 综上所述,除了我遇到的最后一个错误,我已经解决了所有问题。

这是我收到的错误消息:

未捕获的错误:模块构建失败:错误:/Users/fdr/Documents/rds/rds/cli-rds/src/app/ui/generate-field.component.ts(340,48):从导出返回公共方法的类型类具有或正在使用私有名称“提示”。)

这是导致错误的问题文件:

import { Component, Input, Output, EventEmitter, OnInit, AfterViewInit, ElementRef, ViewChild } from '@angular/core';
import { EventHandler } from '../app.event-handler';
import  '../app.utils';

@Component({
    selector: 'app-generate-field',
    templateUrl: 'app/ui/generate-field.component.html',
    styleUrls: ['app/ui/generate-field.component.css']

})
export class GenerateField extends EventHandler
{

    public get hasFocus(): boolean
    {
        return this._hasFocus;
    }

    @Input() delay: number = 300;


    @ViewChild('inputField') private inputField: ElementRef;


    @ViewChild('suggestionField') private suggestionField: ElementRef;


    @Input() public value: string;


    @Output() private valueChange: EventEmitter<string> = new EventEmitter<string>();


    @Output() public keyup: EventEmitter<KeyboardEvent> = new EventEmitter<KeyboardEvent>();

    @Output() public focus = new EventEmitter<KeyboardEvent>();

    @Output() public blur = new EventEmitter<KeyboardEvent>();

    private inlineSuggestion: string;

    private suggestions: ISuggestion[];

    @Input() public options: string[];

    @Output() private optionsChange: EventEmitter<string[]> = new EventEmitter<string[]>();

    private isDirty: boolean = false;

    private _hasFocus: boolean = false;


    constructor(myElement: ElementRef)
    {
        super();


        this.defineObservableProperty('value');
        this.defineObservableProperty('isDirty');
        this.defineObservableProperty('suggestions');
        this.defineObservableProperty('options');

        this.addPropertyListener('isDirty', function ()
        {
            if (this.isDirty == false)return;

            var delay = this.delay ? this.delay : 500;

            var self = this;

            setTimeout(function ()
            {
                self.updateSuggestions();

                this.isDirty = false;

            }.bind(this), delay);

        }.bind(this));

        this.addPropertyListener('value', (): void=>
        {
            this.valueChange.emit(this.value);

            this.isDirty = true;
        });

        this.addPropertyListener('suggestions', (): void=>
        {
            this.updateInlineSuggestion();
        });

        this.addPropertyListener('options', ()=>
        {
            this.optionsChange.emit(this.options);
        });

    }

    //--------------------------------------------------------
    // Functions
    //--------------------------------------------------------

    /**
     * Evaluates value and updates the list of suggestions
     */
    public updateSuggestions(): void
    {
        // Update suggestions
        this.suggestions = this.generateSuggestions(this.value);
    }

    /***
     * Updates the inline suggestion that appears on the text field
     */
    private updateInlineSuggestion(): void
    {
        // Clear inline if there are no suggestions
        if (this.suggestions.length == 0)
        {
            this.inlineSuggestion = '';
            return;
        }

        // Show first option inline
        this.inlineSuggestion = this.suggestions[0].value;

        var x = this.inputField.nativeElement.selectionStart;
        var y = this.inputField.nativeElement.selectionEnd;

        this.suggestionField.nativeElement.selectionStart = x;
        this.suggestionField.nativeElement.selectionEnd = y;

        this.inputField.nativeElement.selectionStart = x;
        this.inputField.nativeElement.selectionEnd = y;

        this.suggestionField.nativeElement.scrollLeft = x;

    }

    private onFocus(): void
    {
        this._hasFocus = true;

        // Forward event
        this.focus.emit();
    }

    private onBlur(): void
    {
        this._hasFocus = false;

        // Forward event
        this.blur.emit();
    }


interface ISuggestion
{

    word: string;

    match: string;

    value: string;
}

尝试在代码的最后部分添加“ 导出接口ISuggestion”,以便也导出ISuggestion。

尝试在任何方法之后添加:。 我遇到了同样的问题,添加任何东西后都解决了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM