ngUpgraders / ng-forward

The default solution for those that want to write Angular 2.x style code in Angular 1.x
411 stars 36 forks source link

@Output not working #94

Closed eesdil closed 8 years ago

eesdil commented 8 years ago

Not sure it is connected to any open issues as I didnt see similar. The binding is working with ouputs: [''] binding but not with @Output

@Component({
    selector: 'so-test',
    controllerAs: 'vm',
    outputs: ['soClick'],
    template: `
        <button type="button" (click)="vm.back()"></button>
        `
})
@Inject('$element')
class Test {
    constructor(private $element) { }

    // @Output('soClick') click = new EventEmitter();

    back() {
        this.$element.triggerHandler('soClick')
    }
}

@Component({
    selector: 'so-test-parent',
    controllerAs: 'vm',
    directives: [Test],
    template: `
        <so-test (so-click)="vm.clicked()"></so-test>
        `
})
@Inject('$element')
class TestParent {
    constructor() { }

    clicked() {
        console.log('parent');
    }
}

This is working, but if I change it to @Ouput it stops working. Using the npm version of ngForward

timkindberg commented 8 years ago

Probably because we forgot to add @Input and @Output to the library's exports :(

We are going to publish a new release soon!

eesdil commented 8 years ago

But I have added to my index:

exports.Input = _decoratorsInputOutput.Input;
exports.Output = _decoratorsInputOutput.Output;

And for Input I had error message when I didnt have it there... Also it is working fine if I add the attributes to the "outputs:[]" and using next with the property

timkindberg commented 8 years ago

Hmm ok. I'll take a look.

timkindberg commented 8 years ago

Try this instead to trigger the event

back() {
    this.click.next()
}

Sorry for the very late response.

timkindberg commented 8 years ago

Is this still broken for you?

timkindberg commented 8 years ago

I'm gonna close this because it's working just fine for me and I don't see any special use-case here. Please reopen if you still have problems.