Multiline string with typescript - Angular2












35















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









share|improve this question





























    35















    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









    share|improve this question



























      35












      35








      35


      4






      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









      share|improve this question
















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      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
























          1 Answer
          1






          active

          oldest

          votes


















          89














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



          var myString = `abc
          def
          ghi`;





          share|improve this answer


























          • 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











          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
          });


          }
          });














          draft saved

          draft discarded


















          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









          89














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



          var myString = `abc
          def
          ghi`;





          share|improve this answer


























          • 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
















          89














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



          var myString = `abc
          def
          ghi`;





          share|improve this answer


























          • 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














          89












          89








          89







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



          var myString = `abc
          def
          ghi`;





          share|improve this answer















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



          var myString = `abc
          def
          ghi`;






          share|improve this answer














          share|improve this answer



          share|improve this answer








          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



















          • 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




















          draft saved

          draft discarded




















































          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.




          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          Monofisismo

          Angular Downloading a file using contenturl with Basic Authentication

          Olmecas