简体   繁体   中英

Angular textarea data binding

I am able to bind the data from a textarea on to the page whilst typing but how am I able to get the returns placed in the textarea?

My current code is:-

app.component.html

  <div class="ui center aligned grid">{{Form.value.address}}</div>

  <form class="ui large form" [formGroup]="Form">
    <div class="ui segment">
      <div class="field">
        <div class="ui input">
          <textarea type="text" name="address" placeholder="Address" formControlName="address"></textarea>
        </div>
      </div>
    </div>
  </form>

app.component.ts

import { Component, OnInit } from '@angular/core';
import {FormBuilder, FormControl, FormGroup} from '@angular/forms';

@Component({
  selector: 'app',
  templateUrl: './app.component.html'
})
export class AppComponent implements OnInit {

  private Form: FormGroup;

  constructor() { }

  ngOnInit() {
    this.Form = new FormGroup({
      address: new FormControl()
    });
  }

}

As you can see from above I can get the data to bind but I am unable bind it as multiple lines, I know I could have multiple boxes to achieve this but I was hoping I would not have to do that.

Any help would be greatly appreciated.

textarea sends line breaks as '\\n' and html shows line breaks with <br/>.

So, you need to convert newline characters from the textarea to <br&gt. Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM