Topic: Preserve line breaks in textarea
steveweller pro asked 6 years ago
Damian Gemza staff answered 6 years ago
import { Component, ViewChild, OnInit, ElementRef } from '@angular/core'; @Component({ selector:'app-root', templateUrl:'./app.component.html', styleUrls: ['./app.component.scss'], }) export class AppComponent implements OnInit { @ViewChild('textarea') textarea: ElementRef; send() { let value=this.textarea.nativeElement.value; console.log(value); } }
<!--Basic textarea--> <div class="md-form"> <textarea #textarea type="text"id="form7"class="md-textarea form-control"mdbInputDirective></textarea> <labelfor="form7">Basic textarea</label> </div> <button mdbBtn color="primary" (click)="send()">Button</button>
FREE CONSULTATION
Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.
Answered
- User: Pro
- Premium support: No
- Technology: MDB Angular
- MDB Version: 6.2.3
- Device: Laptop
- Browser: Chrome
- OS: WIndows 10
- Provided sample code: No
- Provided link: No
Damian Gemza staff commented 6 years ago
Dear Steve, What do you mean by "preserve any line breaks the user has entered." ? Do you want to send the text from the textarea field with every line break which user has entered? Best Regards, Damiansteveweller pro commented 6 years ago
Hi Damien, Yes, that's exact;y right. If the user enters: A B C D I want to preserve those linebreaks when I get the text. At the moment I either get 'A B C D' or worse 'ABCD'. Thanks, Steve