HiveBrain v1.2.0
Get Started
← Back to all entries
patterntypescriptangularCritical

TypeScript - Angular: Multiline string

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
angulartypescriptmultilinestring

Problem

I'm an Angular 2 beginner and I've written this piece of code in my dev/app.component.ts:

import {Component} from 'angular2/core';

@Component({
selector: 'my-app',
template: ' {{contact.firstName}} {{content.lastName}}'
})
export class AppComponent {
public contact = {firstName:"Max", lastName:"Brown", phone:"3456732", email:"max88@gmail.com"};

public showDetail = false;
onSelect() {
this.showDetail=true;
}
}


It works, when I go to the browser "Max Brown is displayed".

Now, I want to write the template part on different lines like this:

import {Component} from 'angular2/core';

@Component({
selector: 'my-app',
template: '
{{contact.firstName}} {{contact.lastName}}'
})
export class AppComponent {
public contact = {firstName:"Max", lastName:"Brown", phone:"3456732", email:"max88@gmail.com"};

public showDetail = false;
onSelect() {
this.showDetail=true;
}
}


But I get this error in Chrome console:

Uncaught TypeError: Cannot read property 'split' of undefined

Solution

Wrap the text in `` (backticks) instead of single quotes '`, then it can span multiple lines.

var myString = `abc
def
ghi`;

Code Snippets

var myString = `abc
def
ghi`;

Context

Stack Overflow Q#35225399, score: 363

Revisions (0)

No revisions yet.