In Angular 2 with TypeScript, I’m trying to format the template part of my component into multiple lines.
Here’s my current code:
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;
}
}
This works fine, displaying “Max Brown” in the browser. However, I want to write the template part on different lines like this:
import { Component } from 'angular2/core';
@Component({
selector: 'my-app',
template: '<h3 (click)="onSelect()">\n {{contact.firstName}} {{contact.lastName}}\n</h3>'
})
export class AppComponent {
public contact = {firstName: "Max", lastName: "Brown", phone: "3456732", email: "max88@gmail.com"};
public showDetail = false;
onSelect() {
this.showDetail = true;
}
}
When I do this, I get an error in the Chrome console: Uncaught TypeError: Cannot read property ‘split’ of undefined. How can I properly write a multi-line string for the template in TypeScript for Angular?