Multiline string with typescript - Angular2
I'm an angular2 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: '<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;
}
}
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: '<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;
}
}
But I get this error in Chrome console:
Uncaught TypeError: Cannot read property 'split' of undefined
typescript angular
add a comment |
I'm an angular2 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: '<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;
}
}
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: '<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;
}
}
But I get this error in Chrome console:
Uncaught TypeError: Cannot read property 'split' of undefined
typescript angular
add a comment |
I'm an angular2 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: '<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;
}
}
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: '<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;
}
}
But I get this error in Chrome console:
Uncaught TypeError: Cannot read property 'split' of undefined
typescript angular
I'm an angular2 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: '<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;
}
}
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: '<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;
}
}
But I get this error in Chrome console:
Uncaught TypeError: Cannot read property 'split' of undefined
typescript angular
typescript angular
edited Jan 3 at 11:29
Luke Van In
4,31411744
4,31411744
asked Feb 5 '16 at 13:26
splunksplunk
2,03093376
2,03093376
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Wrap the text in `
(backticks) instead of single quotes '
, then it can span multiple lines.
var myString = `abc
def
ghi`;
it works at my place....but why is it not possible with the usual '' like in every other language? for example JS itself...
– messerbill
Feb 2 '17 at 15:30
3
Seems you can use normal quotes stackoverflow.com/questions/805107/…. Backticks also allow interpolation developer.mozilla.org/en/docs/Web/JavaScript/Reference/…
– Günter Zöchbauer
Feb 2 '17 at 15:42
ah got it, thank you
– messerbill
Feb 2 '17 at 16:01
2
how can I ignore spaces and new lines?
– Sunil Garg
Jan 31 '18 at 6:47
Sorry, I don't understand the question. Why would you add them in the first place if you don't want them. I don't understand what problem you're trying to solve.
– Günter Zöchbauer
Jan 31 '18 at 6:52
|
show 2 more comments
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f35225399%2fmultiline-string-with-typescript-angular2%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Wrap the text in `
(backticks) instead of single quotes '
, then it can span multiple lines.
var myString = `abc
def
ghi`;
it works at my place....but why is it not possible with the usual '' like in every other language? for example JS itself...
– messerbill
Feb 2 '17 at 15:30
3
Seems you can use normal quotes stackoverflow.com/questions/805107/…. Backticks also allow interpolation developer.mozilla.org/en/docs/Web/JavaScript/Reference/…
– Günter Zöchbauer
Feb 2 '17 at 15:42
ah got it, thank you
– messerbill
Feb 2 '17 at 16:01
2
how can I ignore spaces and new lines?
– Sunil Garg
Jan 31 '18 at 6:47
Sorry, I don't understand the question. Why would you add them in the first place if you don't want them. I don't understand what problem you're trying to solve.
– Günter Zöchbauer
Jan 31 '18 at 6:52
|
show 2 more comments
Wrap the text in `
(backticks) instead of single quotes '
, then it can span multiple lines.
var myString = `abc
def
ghi`;
it works at my place....but why is it not possible with the usual '' like in every other language? for example JS itself...
– messerbill
Feb 2 '17 at 15:30
3
Seems you can use normal quotes stackoverflow.com/questions/805107/…. Backticks also allow interpolation developer.mozilla.org/en/docs/Web/JavaScript/Reference/…
– Günter Zöchbauer
Feb 2 '17 at 15:42
ah got it, thank you
– messerbill
Feb 2 '17 at 16:01
2
how can I ignore spaces and new lines?
– Sunil Garg
Jan 31 '18 at 6:47
Sorry, I don't understand the question. Why would you add them in the first place if you don't want them. I don't understand what problem you're trying to solve.
– Günter Zöchbauer
Jan 31 '18 at 6:52
|
show 2 more comments
Wrap the text in `
(backticks) instead of single quotes '
, then it can span multiple lines.
var myString = `abc
def
ghi`;
Wrap the text in `
(backticks) instead of single quotes '
, then it can span multiple lines.
var myString = `abc
def
ghi`;
edited Mar 4 '17 at 16:51
answered Feb 5 '16 at 13:27
Günter ZöchbauerGünter Zöchbauer
334k721009942
334k721009942
it works at my place....but why is it not possible with the usual '' like in every other language? for example JS itself...
– messerbill
Feb 2 '17 at 15:30
3
Seems you can use normal quotes stackoverflow.com/questions/805107/…. Backticks also allow interpolation developer.mozilla.org/en/docs/Web/JavaScript/Reference/…
– Günter Zöchbauer
Feb 2 '17 at 15:42
ah got it, thank you
– messerbill
Feb 2 '17 at 16:01
2
how can I ignore spaces and new lines?
– Sunil Garg
Jan 31 '18 at 6:47
Sorry, I don't understand the question. Why would you add them in the first place if you don't want them. I don't understand what problem you're trying to solve.
– Günter Zöchbauer
Jan 31 '18 at 6:52
|
show 2 more comments
it works at my place....but why is it not possible with the usual '' like in every other language? for example JS itself...
– messerbill
Feb 2 '17 at 15:30
3
Seems you can use normal quotes stackoverflow.com/questions/805107/…. Backticks also allow interpolation developer.mozilla.org/en/docs/Web/JavaScript/Reference/…
– Günter Zöchbauer
Feb 2 '17 at 15:42
ah got it, thank you
– messerbill
Feb 2 '17 at 16:01
2
how can I ignore spaces and new lines?
– Sunil Garg
Jan 31 '18 at 6:47
Sorry, I don't understand the question. Why would you add them in the first place if you don't want them. I don't understand what problem you're trying to solve.
– Günter Zöchbauer
Jan 31 '18 at 6:52
it works at my place....but why is it not possible with the usual '' like in every other language? for example JS itself...
– messerbill
Feb 2 '17 at 15:30
it works at my place....but why is it not possible with the usual '' like in every other language? for example JS itself...
– messerbill
Feb 2 '17 at 15:30
3
3
Seems you can use normal quotes stackoverflow.com/questions/805107/…. Backticks also allow interpolation developer.mozilla.org/en/docs/Web/JavaScript/Reference/…
– Günter Zöchbauer
Feb 2 '17 at 15:42
Seems you can use normal quotes stackoverflow.com/questions/805107/…. Backticks also allow interpolation developer.mozilla.org/en/docs/Web/JavaScript/Reference/…
– Günter Zöchbauer
Feb 2 '17 at 15:42
ah got it, thank you
– messerbill
Feb 2 '17 at 16:01
ah got it, thank you
– messerbill
Feb 2 '17 at 16:01
2
2
how can I ignore spaces and new lines?
– Sunil Garg
Jan 31 '18 at 6:47
how can I ignore spaces and new lines?
– Sunil Garg
Jan 31 '18 at 6:47
Sorry, I don't understand the question. Why would you add them in the first place if you don't want them. I don't understand what problem you're trying to solve.
– Günter Zöchbauer
Jan 31 '18 at 6:52
Sorry, I don't understand the question. Why would you add them in the first place if you don't want them. I don't understand what problem you're trying to solve.
– Günter Zöchbauer
Jan 31 '18 at 6:52
|
show 2 more comments
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f35225399%2fmultiline-string-with-typescript-angular2%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown