I am using Ionic, and have a ion-textarea i would like to auto size, i.e. expand as the user adds more text. I have found ionic2-autosize, which is a directive. However, I cannot seem to make this directive have any effect on my ion-textarea, i.e. it does not expand as the user adds more text.
I run:
npm install --save ionic2-autosize
package.json
"ionic2-autosize": "^1.1.1",
app.module.ts
import {Autosize} from 'ionic2-autosize';
@NgModule({
declarations: [
MyApp, Autosize
],
...
review.ts
<ion-textarea autosize [(ngModel)]="ratingModel.review" formControlName="review" id="review"></ion-textarea>
As you can see, I add the autosize attribute to the ion-textarea, but this has no effect, it behaves like a regular ion-textarea with only a height of 2 lines. I would expect the height to expand dynamically.
Any help appreciated.
More info:
global packages:
@ionic/cli-utils : 1.1.2
Cordova CLI : 6.4.0
Ionic CLI : 3.1.2
local packages:
@ionic/app-scripts : 1.3.0
@ionic/cli-plugin-cordova : 1.1.2
@ionic/cli-plugin-ionic-angular : 1.1.2
Ionic Framework : ionic-angular 3.2.1
System:
Node : v7.10.0
OS : macOS Sierra
Xcode : Xcode 8.3.2 Build version 8E2002
ios-deploy : not installed
ios-sim : not installed
UPDATE
I add the AutosizeModule to my module:
review.module.ts
import {AutosizeModule} from 'ionic2-autosize';
@NgModule({
declarations: [ReviewPage],
imports: [IonicPageModule.forChild(ReviewPage), ControlMessagesModule, RatingComponentUpdateableModule, AutosizeModule],
exports: [ReviewPage]
})
export class ReviewPageModule { }
But get this error:
ERROR Error: Uncaught (in promise): Error: Type Autosize is part of the declarations of 2 modules: AppModule and AutosizeModule! Please consider moving Autosize to a higher module that imports AppModule and AutosizeModule. You can also create a new NgModule that exports and includes Autosize then import that NgModule in AppModule and AutosizeModule.
UPDATE
I removed it from the app.module.ts, and it seems to have fixed the above error. However, now I get:
ERROR Error: Uncaught (in promise): Error: BrowserModule has already been loaded. If you need access to common directives such as NgIf and NgFor from a lazy loaded module, import CommonModule instead. Error: BrowserModule has already been loaded. If you need access to common directives such as NgIf and NgFor from a lazy loaded module, import CommonModule instead.
UPDATE
Rather used CommonModule:
review.module.ts
//import {AutosizeModule} from 'ionic2-autosize';
import { CommonModule } from '@angular/common';
@NgModule({
declarations: [ReviewPage],
imports: [IonicPageModule.forChild(ReviewPage), ControlMessagesModule, RatingComponentUpdateableModule, CommonModule],
exports: [ReviewPage]
})
export class ReviewPageModule { }
app.module.ts
import { AutosizeModule } from 'ionic2-autosize';
...
@NgModule({
declarations: [
MyApp
],
imports: [
IonicModule.forRoot(MyApp),
BrowserModule,
AutosizeModule,
HttpModule,
AngularFireModule.initializeApp(firebaseConfig),
IonicStorageModule.forRoot()
],
The errors went away, but the ion-textarea still does not autosize.
AutosizeModulefrom? I was not aware I had to import it? Is it part ofionic2-autosize? - RichardAutosizeModule, but am getting an error. - RichardAutosizeModulewithCommonModulein myreview.module.ts. I now get no errors. But I am back to square one, theion-textareadoes not autosize. - RichardAutosizeModuleback toapp.module.ts, and there is no errors, but also no autosizing. - Richard