【发布时间】:2016-03-15 10:44:36
【问题描述】:
我是 Angular 2 的新手。我刚刚在 Angular 2 中创建了一个基本组件。该组件正在工作,但是当我在 HTML 中多次调用该组件时,它仅适用于第一次调用。
下面是app.component.ts
import {Component} from 'angular2/core';
import {bootstrap} from 'angular2/platform/browser'
@Component({
selector: 'click-me',
template: `<input #box (keyup.enter)="values=box.value"
(blur)="onKey(box.value)" />`
})
export class AppComponent {
clickMessage = '';
onKey(value: string) {
}
onClickMe() {
this.clickMessage = 'You are my hero!';
}
bootstrap(AppComponent);
当我在主 index.html 中多次使用 '<click-me></click-me>' 时,它适用于第一个。
下面是index.html
<html>
<script>
System.config({
packages: {
app: {
format: 'register',
defaultExtension: 'js'
}
}
});
System.import('app/app.component')
.then(null, console.error.bind(console));
</script>
</head>
<!-- 3. Display the application -->
<body>
<click-me></click-me>
<click-me></click-me>
</body>
</html>
【问题讨论】:
标签: angular