导航失败:模板解析错误:无法绑定到"选项",因为它不是 'signature-pad' 的已知属性



我试图在我的离子3项目中实现Angular2签名垫,我在上面的问题上遇到错误。我关注此教程链接。它在离子2中工作正常,但是当我尝试使用离子3时,我会遇到以下错误的错误

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

您可以像我只是尝试此https://devdactic.com/signature-drawpad-ionic-2/

中的所有内容一样获得完整的代码。

我认为,当我使用deeplink导航时,我会遇到此错误,但是当我将组件导入app.module.ts时,一切正常

更新

这是我的.ts文件

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();
  }
}

这是我的.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>

我也面临着这个问题。我通过在DevDactic https://devdactic.com/signature-drawpad-ionic-2/

上浏览原始帖子的评论解决了这个问题。

一个名叫Ka Mok的家伙向我指出了一些东西

如果您在组件中使用签名垫。就我而言,是在农民组成部分中使用的,该组件通常具有farmer.module.ts文件。因此,只需导入签名垫模块,一切都应该正常工作

例如

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';

最后确保您还将模块导入app.module.ts

我希望这对某人有帮助。谢谢

您需要将模块添加到导入

import { SignaturePadModule } from 'angular2-signaturepad';
@NgModule({
  imports: [/* BrowserModule, RouterModule.forRoot(myRoutes), ... */,
      SignaturePadModule],
  ...
})
export class AppModule {
}

其中AppModule是同一模块,该模块还包含declarations: [...]使用签名板的组件中。

Confirm.module.ts中导入SignaturePadModule,因为您正在使用离子3。

@NgModule({
    declarations: [
        ConfirmSign
    ],
    imports: [
        IonicPageModule.forChild(ConfirmSign),
        SignaturePadModule
    ],
    entryComponents: [
        ConfirmSign
    ]
})
export class ConfirmSignModule { }

相关内容

  • 没有找到相关文章

最新更新