我是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;
}
}
当我转到浏览器“显示最大布朗”时,它可以工作。
现在,我想在不同的行上编写模板部分,如下所示:
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