【问题标题】:AngularJS custom input directive. Overriding default input directiveAngularJS 自定义输入指令。覆盖默认输入指令
【发布时间】:2014-02-25 11:04:33
【问题描述】:

我正在尝试创建自定义输入指令,它将覆盖复选框输入的默认行为。我似乎找不到阻止默认复选框输入指令执行的解决方案。

我尝试只装饰输入,自定义指令的优先级设置为 0。

<input type="checkbox" my-custom-directive="0" ng-model="MyList" />

我也尝试过使用模板并替换不同的元素类型。

<div my-custom-directive="0" ng-model="MyList"></div>
// part of directive object
return {
    restrict: 'A',
    template: '<input type="checkbox" />',
    replace: true,
    terminal: true,
    priority: 0, ...
}

最终我要做的是将复选框输入绑定到数组,并创建行为,如果某个值是数组的成员,则将检查输入,否则将不检查。此外,如果用户选中输入框,指令会将提到的值添加到数组中。

【问题讨论】:

    标签: angularjs angularjs-directive


    【解决方案1】:

    最后我通过使用 ngNonBindable 指令解决了这个问题。我真的不喜欢这个解决方案,因为在更复杂的场景中,我可能仍想对模板的某些元素使用绑定。如果其他人有更好的想法,我会在出现时接受该答案。

    return {
        restrict: 'A',
        template: '<input type="checkbox" ng-non-bindable />',
        replace: true,
        terminal: true,
        priority: 0, ...
    }
    

    【讨论】:

      猜你喜欢
      • 2017-10-29
      • 2014-08-28
      • 2023-04-01
      • 2019-01-04
      • 1970-01-01
      • 2017-03-03
      • 2013-05-17
      • 2014-02-14
      • 1970-01-01
      相关资源
      最近更新 更多