Ionic framework 角度2 ES6-从组件发送事件

Ionic framework 角度2 ES6-从组件发送事件,ionic-framework,angular,ecmascript-6,ionic2,Ionic Framework,Angular,Ecmascript 6,Ionic2,我想从ES6中的组件发送一个自定义事件,这样我就可以在模板中侦听它,但我无法使它发生 @组件的属性输出或事件正在破坏应用程序。我错过什么了吗 这是我的组件声明: import {Component, Output} from 'angular2/core'; @Component({ selector: 'section-navigator-component', templateUrl: 'build/components/section_navigator/section_

我想从ES6中的组件发送一个自定义事件,这样我就可以在模板
中侦听它,但我无法使它发生

@组件的
属性
输出
事件
正在破坏应用程序。我错过什么了吗

这是我的组件声明:

import {Component, Output} from 'angular2/core';

@Component({
    selector: 'section-navigator-component',
    templateUrl: 'build/components/section_navigator/section_navigator.html',
    inputs: [ 'resources', 'attr' ],
    outputs: [ 'someEvent' ]
})


export class SectionNavigatorComponent {
    constructor() {

    }

    resourceClickHandler($event, resource) {

    }
}

这应该适用于您的情况:

import {Component, Output, EventEmitter} from 'angular2/core';

@Component({
    selector: 'section-navigator-component',
    templateUrl: 'build/components/section_navigator/section_navigator.html',
    inputs: [ 'resources', 'attr' ],
    outputs: [ 'someEvent' ]
})


export class SectionNavigatorComponent {

    constructor() {
      this.someEvent = new EventEmitter();
    }

    resourceClickHandler($event, resource) {
      this.someEvent.emit(someValue);
    }
}

除非使用下面的备选类型脚本语法,否则不需要导入“输出”:

import {Component, Input, Output, EventEmitter} from 'angular2/core';

@Component({
    selector: 'section-navigator-component',
    templateUrl: 'build/components/section_navigator/section_navigator.html'
})


export class SectionNavigatorComponent {
    @Input() resources: any;
    @Input() attr: any;

    @Output() someEvent: EventEmitter<any> = new EventEmitter();

    constructor() {
    }

    resourceClickHandler($event, resource) {
      this.someEvent.emit(someValue);
    }
}
import{Component,Input,Output,EventEmitter}来自'angular2/core';
@组成部分({
选择器:“节导航器组件”,
templateUrl:'build/components/section\u navigator/section\u navigator.html'
})
导出类节导航组件{
@Input()资源:任意;
@Input()属性:任意;
@Output()someEvent:EventEmitter=neweventemitter();
构造函数(){
}
resourceClickHandler($event,resource){
this.someEvent.emit(someValue);
}
}

请添加代码,说明您尝试了什么以及失败的地方。您收到错误消息了吗?我更新了问题您是否正确导入了某个事件?导入是什么意思?someEvent必须是扩展一些基本事件类的类吗?我不认为组件装饰器中有一个关键的输入或输出,但我认为我错过了一些东西,因为API仍然变化很大。是的,通常你会在类
@Input()
@Output()
中使用它。对于事件,别忘了从Core导入输入和输出修饰符。感谢你的回答,我能够解决我的问题。您很接近,唯一缺少的是从“angular2/core”导入{EventEmitter}遗憾的是它没有抛出任何错误。无论如何,谢谢