【问题标题】:Using ngPaste with Angular Formly使用 ngPaste 和 Angular Formly
【发布时间】:2015-12-22 11:46:43
【问题描述】:

我正在使用 Angular Formly 构建一个简单的表单。

我需要在其中一个输入字段中禁用粘贴。早些时候,我禁用了 ng-Paste 默认事件,如下面的答案所述:https://stackoverflow.com/a/27783611/3156644

但是,既然表单生成现在由 Formly 完成,我如何有条件地将带有函数($event.preventDefault) 的指令添加到 Formly 生成的字段中?

我能想到的一个选项是创建一个新模板,但这看起来不像是 DRY 代码。还有另一种方法吗?

【问题讨论】:

    标签: angularjs validation angular-formly


    【解决方案1】:

    扩展现有模板对我来说已经足够 DRY 了:

    formlyConfig.setType({
      name: 'nopaste-input',
      extends: 'input', // Extend regular input
      link: function(scope, el, attrs) {}, // Add functionality here
      // etc...
    });
    

    自定义模板文档:http://docs.angular-formly.com/docs/custom-templates#creating-a-custom-template

    引导类型:https://github.com/formly-js/angular-formly-templates-bootstrap/tree/master/src/types

    【讨论】:

      猜你喜欢
      • 2018-02-16
      • 2013-08-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多