skid
skid

Reputation: 978

new line while concatenation of string in Typescript

I am working on Angular2 in which i need to create a new line for my dynamically created string.

eg.

input:

Hello how are you ?

output:

Hello

how

are

you?

Here is my code:

.html

<div class="row">
                <div class="well">
                    <h1 class="text-center">Import Data</h1>
                    <p class="text-center">{{selectedLogContent.message}}</p>
                </div>
            </div>

this is the typescript code:

var splitString = selectedRows[0].description.split(":");
            var messageString= splitString[3].split(".");
            var messageStringAfter ="";
            for(var i=0;i<messageString.length;i++){
                messageStringAfter= messageStringAfter+`\ 
                \n`+messageString[i];
            }
            var finalString = splitString[0]+":"+splitString[1]+":"+splitString[2]+': '+messageStringAfter;
            console.log(finalString);
            this.selectedLogContent.message = finalString;

I tried using '\n' while concatenation of the string still ending up the output in the same line.

Thanks in advance

Upvotes: 2

Views: 7321

Answers (1)

Aravind
Aravind

Reputation: 41553

There is nothing big with angular2 to do here all you need is a *ngFor to achieve as below,

<div *ngFor="let s of values.split(' ')">
      {{s}} <br/>
</div> 

LIVE DEMO

Upvotes: 5

Related Questions