Javascript Angular2 LifecycleEvent.onChange未启动

Javascript Angular2 LifecycleEvent.onChange未启动,javascript,angular,Javascript,Angular,在撰写本文时,我使用的是Angular 2.0.0-alpha.36。 在以下代码中,除onChange外,所有功能均按预期运行: /// <reference path="../../typings-custom/_custom.d.ts" /> import {Component, View, LifecycleEvent} from 'angular2/angular2'; @Component({ selector: 'counter', lifecycl

在撰写本文时,我使用的是Angular 2.0.0-alpha.36。 在以下代码中,除onChange外,所有功能均按预期运行:

/// <reference path="../../typings-custom/_custom.d.ts" />

import {Component, View, LifecycleEvent} from 'angular2/angular2';

@Component({
    selector: 'counter',
    lifecycle: [LifecycleEvent.onInit, LifecycleEvent.onChange, LifecycleEvent.onCheck, LifecycleEvent.onAllChangesDone]
})
@View({
    template: '<button (click)="increment()">Increase Component {{count}}</button>'
})

export class Counter {

    count: number = NaN;

    constructor()
    {
        this.count = 0;
    }

    increment()
    {
        ++this.count;
    }

    onInit()
    {
        console.log('onInit');
    }

    onCheck()
    {
        console.log('onCheck');
    }

    onChange(changes)
    {
        console.log('onChange');
        console.log(changes);
    }

    onAllChangesDone()
    {
        console.log('onAllChangesDone');
    }
}
//
从'angular2/angular2'导入{Component,View,LifecycleEvent};
@组成部分({
选择器:'计数器',
lifecycle:[LifecycleEvent.onInit、LifecycleEvent.onChange、LifecycleEvent.onCheck、LifecycleEvent.onAllChangesOne]
})
@看法({
模板:“增加组件{{count}}”
})
出口类柜台{
计数:number=NaN;
构造函数()
{
此值为0.count;
}
增量()
{
++这个.伯爵;
}
onInit()
{
console.log('onInit');
}
onCheck()
{
log('onCheck');
}
变更(变更)
{
console.log('onChange');
控制台日志(更改);
}
onAllChangesDone()
{
log('onAllChangesDone');
}
}
除了大量堆栈溢出搜索外,我还引用了几个线程,包括:

如果有任何帮助,我们将不胜感激。

onChange()
将在组件输入绑定发生更改时触发


问题是,
计数器
组件没有输入属性(输入绑定),因此从未调用on
onChange()
事件。

。你基本上必须改变引用,而不是值。你能解释一下Oninit和Constructor之间的区别吗?哪一个是第一个调用的?构造函数是第一个调用的,然后在init上,在加载模板之前或加载到模板之后调用AFIKis-Oninit?最好的方法是在Oninit中放置一个断点,然后检查开发工具的网络选项卡,查看是否发出了模板请求(在移动设备上,我现在不能尝试自己)