簡體   English   中英

ES5 中的 Angular2 輸出?

[英]Angular2 Outputs in ES5?

這是使用 ES5 演示 Angular 2 中的輸出的示例代碼。 但是我收到一個TypeError: Cannot read property 'subscribe' of undefined error。

var SampleComponent10 = ng.core.Component({
    selector: "sampleten",
    outputs: ["click"],
    template: ""
}).Class({
    constructor: function(){
        setInterval(function(){
            this.click.next({});
        }.bind(this), 10000)
    }
})

var SampleComponent11 = ng.core.Component({
    selector: "sampleeleven",
    directives: [SampleComponent10],
    template: "<sampleten (click)='clicked($event)'></sampleten>"
}).Class({
    constructor: function(){
        this.clicked = function(e){
            console.log(e);
            console.log("Clicked");
        }
    }
})

SampleComponent11 的模板似乎有一些錯誤。 但我無法抓住它

您需要像這樣更改代碼:

var SampleComponent10 = ng.core.Component({
    selector: "sampleten",
    outputs: ["click"],
    template: ""
}).Class({
    constructor: function(){
        this.click = new ng.core.EventEmitter(); <== add this line
        setInterval(function(){
            this.click.next({});
        }.bind(this), 10000)
    }
})

另見https://angular.io/docs/ts/latest/cookbook/ts-to-js.html#!#property-metadata

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM