[英]Angular2 Click Event Not Updating Template
I'm experimenting with Angular2 and trying to get a simple click event to update a template. 我正在尝试使用Angular2,并尝试获取一个简单的click事件来更新模板。 The click event fires the
toggleValue()
function, but does not update the template. click事件会触发
toggleValue()
函数,但不会更新模板。 What I've done seems to be in line with various tutorials out there (though they're based on the Alpha version); 我所做的工作似乎与那里的各种教程保持一致(尽管它们基于Alpha版本)。 I just can't figure out where I'm going wrong with such a simple example.
通过这样一个简单的示例,我无法弄清楚哪里出了问题。 Code as follows:
代码如下:
/// <reference path="typings/tsd.d.ts" /> import 'reflect-metadata'; import {Component, View} from 'angular2/core'; import {bootstrap} from 'angular2/bootstrap'; @Component({ selector: 'app', }) @View({ template: ` <div>Value: {{value}}</div> <button (click)="toggleValue()">Toggle</button> ` }) class App { value: boolean = true; toggleValue () { console.log('toggleValue()'); this.value = !this.value; } } bootstrap(App);
I'm using Angular version 2.0.0-beta.0 我正在使用Angular 2.0.0-beta.0版本
Perhaps it could be, because you didn't include the angular-polyfills.js
file. 可能是因为您没有包含
angular-polyfills.js
文件。 The latter contains the support of zones, that are responsible for detecting updates of component fields. 后者包含区域的支持,这些区域负责检测组件字段的更新。 That way, templates can then be updated to take into account new values...
这样,模板就可以更新以考虑新值了。
Do you include this file in the index.html
file of your application? 您是否将此文件包含在应用程序的
index.html
文件中?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.