【问题标题】:Angular JS - TypeError: Cannot call method 'getContext' of nullAngular JS - TypeError:无法调用 null 的方法“getContext”
【发布时间】:2016-01-04 07:29:17
【问题描述】:

我是混合应用程序的新手,并使用 Ionic 框架开发应用程序,我想在其中实现 ng-repeat 内的多个签名板。画布以定义的 css 规范显示。但是,签名的绘图不起作用。

signature.html

 <div   ng-repeat="esign in consent" > 
 <div ><!--Signature Pad -->
    <canvas  id="{{'canvas'+$index}}"  ng-init="createSigPad($index)" width='300' height='180'  style='border: 1px solid blue;'></canvas>
    <div class='button-bar'>
    <a class='button button-energized' >Clear</a>
    <a class='button button-balanced' >Save</a>
    </div>
    </div> 
    </div>

controller.js

$scope.createSigPad=function(index){

     // alert(document.getElementById('canvas'+index).id);
     new SignaturePad(document.getElementById('canvas'+index));

}

在 Logcat 中我看到 TypeError: Cannot call method 'getContext' of null

注意:当我在 ng-repeat 之外尝试单个签名板时,它工作正常

请帮我找到解决办法。

【问题讨论】:

    标签: html angularjs cordova ionic-framework signaturepad


    【解决方案1】:

    尝试将 ng-init 更改为 ng-click 以检查它是否工作,问题我需要等到 ng-repeat 完成然后调用 createSigPad, 最好用指令来做到这一点。

    你可以试试这个选项: 你的html需要是

    <canvas  ng-init="createSigPad($event)" width='300' height='180'  style='border: 1px solid blue;'></canvas>
    

    你的功能需要是:

    $scope.createSigPad=function($event){
    
     new SignaturePad($event.currentTarget);
    

    }

    这样你就得到了元素目标

    【讨论】:

    • 如何使用指令执行此操作?你能指导我吗? @Avishai Peretz
    • 如果这些更改对您有帮助,请告诉我。
    猜你喜欢
    • 2012-05-26
    • 1970-01-01
    • 1970-01-01
    • 2014-08-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多