最佳答案
我是一个 Angular 2的初学者,我在我的 dev/app.component.ts
中写了这段代码:
import {Component} from 'angular2/core';
@Component({
selector: 'my-app',
template: '<h3 (click)="onSelect()"> {{contact.firstName}} {{content.lastName}}</h3>'
})
export class AppComponent {
public contact = {firstName:"Max", lastName:"Brown", phone:"3456732", email:"max88@gmail.com"};
public showDetail = false;
onSelect() {
this.showDetail=true;
}
}
当我进入浏览器“ Max Brown 被显示”时,它就工作了。
现在,我想在不同的行上编写模板部分,如下所示:
import {Component} from 'angular2/core';
@Component({
selector: 'my-app',
template: '<h3 (click)="onSelect()">
{{contact.firstName}} {{contact.lastName}}<h3>'
})
export class AppComponent {
public contact = {firstName:"Max", lastName:"Brown", phone:"3456732", email:"max88@gmail.com"};
public showDetail = false;
onSelect() {
this.showDetail=true;
}
}
但是我在 Chrome 控制台中得到了这个错误:
Uncaught TypeError: Cannot read property 'split' of undefined