How to use preg_replace in angualr? [duplicate]

  angular, javascript, node.js

I have need a text-area data to be view on same alignment using line break and line space in post data..

I have used on angular 10 project and using data base on firebase.

I have some code and images are attached

if incase any mistakes and change anything plz answer me..

this way to correct or not ,, this way not working final data on display

code:

    <form class="post-text d-flex align-items-center ml-3 w-100" #form="ngForm" (ngSubmit)="postMessage123(form); form.reset();" style="margin-right: 1rem;">
                      
        <textarea name="message" ngModel id="msg" type="text" class="form-control rounded" placeholder="Write something here..." style="border: 1px solid black;line-height: 1;" rows="5"></textarea>
        <button  type="submit" [disabled]="form.invalid || form.pending"  *ngIf="!form.pending" (click)="notification()" class="btn"  style="width: 6rem;border-radius: 40px;padding: 3px 6px;background-color: #3f51b5;border-color: #3f51b5;color: white;">Post</button>
    </form>
</div>
<hr>
<h5>{{text2}}</h5>

TypeScript file:

postMessage123(form: NgForm): void{
    alert('workinf')
    const {message} = form.value;
    this.text = message;
    this.text = this.text.replace(/  /g, "&nbsp;");
    this.text = this.text.replace(/n/g, "<br>n");
    alert(this.text)

    this.text2 = this.text;
    this.text2 = this.text2.preg_replace("#[sp]#", "&nbsp;", this.text2);
    this.text2 = this.text2.preg_replace("#[nl]#", "<br>n", this.text2);
    alert(this.text2)
}

Output:

enter image description here

Source: Angular Questions

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.