简体   繁体   English

用于签名板的角形自定义模板

[英]angular-formly custom template for signature pad

So I'm trying to write a custom template for the angular-formly librarythat uses the signature pad directive as a field. 因此,我正在尝试为使用签名板指令作为字段的角度形式库编写自定义模板。 I've been able to use the basic template method to get the signature pad to show up: 我已经能够使用基本模板方法来显示签名板:

app.run(function(formlyConfig) {
    formlyConfig.setType({
        name: 'signaturePad',
        template: '<signature-pad accept="accept" clear="clear"' +
            'height="220" width="568"></signature-pad>' +
            '<button ng-click="clear()">Clear signature</button>' +
            '<button ng-click="signature = accept()">Sign</button>'
    });
});

However, the issue that I'm having is that the signature variable that accepts the return value once the Accept button is clicked is not accessible in the scope of the main controller. 但是,我遇到的问题是,一旦单击“接受”按钮,就无法在主控制器的范围内访问接受返回值的signature变量。

Perhaps a clearer version of the problem would be: 问题的一个更清晰的版本可能是:

 app.run(function(formlyConfig) {
    formlyConfig.setType({
        name: 'helloWorldButton',
        template: '<button ng-click="vm.clicked()">Sign</button>'
    });
});

How can I access the a function vm.clicked() inside of the application controller. 如何访问应用程序控制器内部的vm.clicked()函数。 The form itself is declared within the ng-controller scope: 表单本身在ng-controller范围内声明:

<div ng-controller="controllerName as ctrl">    
    <form ng-submit="ctrl.onSubmit()">
        <formly-form model="ctrl.userData" fields="ctrl.userFields">
            <button type="ctrl.submit">Submit</button>
        </formly-form>
    </form>
</div>

I managed to figure a different way of getting this to work, for anyone concerned. 对于所有相关人员,我设法找到了使之生效的另一种方法。

app.run(function(formlyConfig) {
    formlyConfig.setType({
        name: 'signaturePad',
        template: '<button ng-click="openSigPad()">Sign</button>',
        controller: function($scope, $uibModal) {
            ...
            $scope.openSigPad = $uibModal.open(...);
            .then(function(result) {
                $scope.model[$scope.options.key] = result;
            });
        }
    });
});

This way, I created a modal using UI Bootstrap, display any necessary info in that, and then return the modal result back to the model of the field itself. 这样,我使用UI Bootstrap创建了一个模态,在其中显示任何必要的信息,然后将模态结果返回给字段本身的模型。 Works great. 效果很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM