ionic2 textarea Automatically grows

本文介绍了一个名为 angular2-elastic 的 npm 包,该包允许文本区域根据内容自动调整大小。通过简单的安装步骤和两步集成指南,开发者可以轻松地将此功能应用于 Angular2 或 Ionic2 项目中。

Installation

npm install angular2-elastic

Quick Start

  1. Import the ElasticModule.
  2. Add the directive fz-elastic to your textarea or ion-textarea.
  3. Watch as your textareas automatically grow and shrink depending on their content.

Angular 2

1. Import the ElasticModule:

import { NgModule }      from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule }   from '@angular/forms';
import { ElasticModule } from 'angular2-elastic';
 
import { AppComponent }  from './app.component';
 
@NgModule({
  imports: [
    BrowserModule,
    FormsModule,
    ElasticModule
  ],
  declarations: [
    AppComponent
  ],
  bootstrap: [ AppComponent ]
})
export class AppModule {}
 

2. Use the directive in your component HTML:

import { Component } from '@angular/core';
 
@Component({
  selector: 'my-app',
  template: `<textarea fz-elastic></textarea>`
})
export class AppComponent {};
 

That's it! Your textarea will now grow and shrink as you type.

The textarea will also respond to changes from any one or two way bindings that are setup, e.g. with [(ngModel)].

 

Ionic 2

  1. Import the module as above.
  2. Use the directive on an ion-textarea instead:
<ion-textarea fz-elastic></ion-textarea>
 
https://github.com/stevepapa/angular2-autosize

转载于:https://www.cnblogs.com/brucejchen/p/7483774.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值