5

I am trying to implement angular2 signature pad in my ionic 3 project i am getting error as above my question. I am following this tutorial link. It is working fine in ionic2 but when i try in ionic 3 i am getting error like below

Failed to navigate:  Template parse errors:
Can't bind to 'options' since it isn't a known property of 'signature-pad'.
1. If 'signature-pad' is an Angular component and it has 'options' input, then verify that it is part of this module.
2. If 'signature-pad' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.
3. To allow any property add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component. ("
    <ion-col></ion-col>
    <ion-col>
      <signature-pad [ERROR ->][options]="signaturePadOptions" (onBeginEvent)="drawStart()" (onEndEvent)="drawComplete()"></signatur"): ng:///ConformsignModule/Conformsign.html@20:21
'signature-pad' is not a known element:
1. If 'signature-pad' is an Angular component, then verify that it is part of this module.
2. If 'signature-pad' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. ("
    <ion-col></ion-col>
    <ion-col>
      [ERROR ->]<signature-pad [options]="signaturePadOptions" (onBeginEvent)="drawStart()" (onEndEvent)="drawComplet"): ng:///ConformsignModule/Conformsign.html@20:6

you can get the full code in this like i just trying everything in this https://devdactic.com/signature-drawpad-ionic-2/

I think when i use deeplink navigation i am getting this error but when i import my component to app.module.ts everything is working fine

update

here is my .ts file

export class Conformsign {

  signature = '';
  isDrawing = false;
  finalData
  @ViewChild(SignaturePad) signaturePad: SignaturePad;
  @Input()
  private signaturePadOptions: Object = { // Check out https://github.com/szimek/signature_pad
    'minWidth': 2,
    'canvasWidth': 400,
    'canvasHeight': 200,
    'backgroundColor': '#f6fbff',
    'penColor': '#666a73'
  };

  constructor(public navCtrl: NavController, public navParams: NavParams, public toastCtrl: ToastController, public holders: Holders, public rest:Rest) {

    this.finalData = this.holders.getData();
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad Conformsign');
  }

  ionViewDidEnter() {
    this.signaturePad.clear()
  }

  drawComplete() {
    this.isDrawing = false;
  }

  drawStart() {
    this.isDrawing = true;
  }

  savePad() {
    this.signature = this.signaturePad.toDataURL();
    this.signaturePad.clear();
    let toast = this.toastCtrl.create({
      message: 'New Signature saved.',
      duration: 3000
    });
    toast.present();

     let conformDelivery = {
      order_id: this.finalData.order_id,
      amountpaid:this.finalData.total,
      customername:this.finalData.firstname,
      signature:this.signature,
      user_id:this.finalData.user_id,
      customer_id:this.finalData.customer_id
    }

  }

  clearPad() {
    this.signaturePad.clear();
  }

}

here is my .html

<ion-content>
  <div class="title">Please draw your Signature</div>
  <ion-row [ngClass]="{'drawing-active': isDrawing}">
    <ion-col></ion-col>
    <ion-col>
      <signature-pad [options]="signaturePadOptions" (onBeginEvent)="drawStart()" (onEndEvent)="drawComplete()"></signature-pad>
    </ion-col>
    <ion-col></ion-col>

  </ion-row>
  <button ion-button full color="danger" (click)="clearPad()">Clear</button>
  <button ion-button full color="secondary" (click)="savePad()">Save</button>

  <ion-row>
    <ion-col></ion-col>
    <ion-col width-80>
      <img [src]="signature"/>
    </ion-col>
    <ion-col></ion-col>
  </ion-row>

</ion-content>
Mohan Gopi
  • 7,606
  • 17
  • 66
  • 117

3 Answers3

8

I was facing this issue also. I solved this issue by going through comments on the original post by devdactic https://devdactic.com/signature-drawpad-ionic-2/

A guy named Ka mok pointed me to something

IF you are using the signature pad in a component . in my case am using it in a farmers component, the component usually have a farmer.module.ts file. So just import the signature pad module and everything should work fine

e.g

farmer.module.ts

import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { FarmerPage } from './farmer';
import { SignaturePadModule } from 'angular2-signaturepad';

@NgModule({
  declarations: [
    FarmerPage,
  ],
  imports: [
    IonicPageModule.forChild(FarmerPage),
    SignaturePadModule // this saved my life
  ],
})
export class FarmerPageModule {}

farmer.ts

import { Component, ViewChild } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { SignaturePad } from 'angular2-signaturepad/signature-pad';
import { NativeStorage } from '@ionic-native/native-storage';
import { ToastController } from 'ionic-angular';

Lastly make sure you also import the module in app.module.ts

I hope this helps someone. Thanks

sannimichaelse
  • 436
  • 5
  • 12
  • 1
    Thanks, just in case some noob (like myself) comes here trying to figure it out for Ionic 4, you need to add it into the import section of your app.module.ts. When installing the plugin from command line it will be auto added to Providers but you also need to manually included in the imports! Thanks! – Emil Borconi Nov 17 '19 at 22:25
0

You need to add the module to imports

import { SignaturePadModule } from 'angular2-signaturepad';

@NgModule({
  imports: [/* BrowserModule, RouterModule.forRoot(myRoutes), ... */,
      SignaturePadModule],
  ...
})
export class AppModule {
}

where AppModule is the same module that also contains in declarations: [...] the component where you are using the signature pad.

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
  • this my app.module.ts file `imports: [ BrowserModule, HttpModule, SignaturePadModule, IonicModule.forRoot(MyApp) ]` but still i am getting this same error – Mohan Gopi Apr 24 '17 at 11:35
  • And `Conformsign` is in `declarations: [...]` of the same `NgModule`? – Günter Zöchbauer Apr 24 '17 at 11:36
  • No in ionic 3 i am using Deeplink navigation so i dont need to import `conformsign` or any other component in app.module.ts file – Mohan Gopi Apr 24 '17 at 11:37
  • i am able to navigate to any other pages in my project except when i go to the `conformsign` page i am getting this error – Mohan Gopi Apr 24 '17 at 11:38
  • It's not related to navigation, it's related to `options`. Either no registered component with the selector `signature-pad` is registered or it doesn't have an `options` input. – Günter Zöchbauer Apr 24 '17 at 11:40
  • yes it is working when import all the component in my app.module.ts file – Mohan Gopi Apr 24 '17 at 11:43
  • Not sure what you mean by your last comment. Could you make it work? What did you have to change? – Günter Zöchbauer Apr 24 '17 at 11:48
  • @if you see my question i have said the in ionic 2 it is working fine ofcourse in ionic 3 when i import all the pages/component in my app.module.ts file i am not getting any error everything is working file when i use deep link navigation i am facing this problem – Mohan Gopi Apr 24 '17 at 11:53
0

Import the SignaturePadModule in Confirm.module.ts since you are using ionic 3.

@NgModule({
    declarations: [
        ConfirmSign
    ],
    imports: [
        IonicPageModule.forChild(ConfirmSign),
        SignaturePadModule
    ],
    entryComponents: [
        ConfirmSign
    ]
})
export class ConfirmSignModule { }
Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
  • I tried the above answer but i am getting this error now `Failed to navigate: Module build failed: Error: ENOENT: no such file or directory, open '/home/panini/checkingv3/node_modules/signature_pad/signature_pad.js'` – Mohan Gopi Apr 24 '17 at 12:32