【问题标题】:why onchange event not fire in angular js?为什么 onchange 事件不会在 Angular js 中触发?
【发布时间】:2014-08-16 02:28:13
【问题描述】:

我正在从 json 制作一个表单。我在 tv4.js 中使用具有依赖性的 angular-schema-form。我从中学习 https://github.com/Textalk/angular-schema-form/blob/master/docs/index.md#global-options 我们可以在元素上应用 onchange 。但是当我应用它时不调用它也没有给出任何错误,为什么? 普朗克 http://plnkr.co/edit/wbziK5aRUg69JuwXDoVy?p=preview

onChange: function(modelValue,form) {
      console.log("Password is",modelValue);
    }

我就是这样用的

"email": {
            "title": "Email",
            "type": "string",
            "minLength": 2,
            "pattern": "^\\S+@\\S+$",
            onChange: function(modelValue,form) {
      console.log("Password is"+modelValue);
          },
            validationMessage: {
              200: "Address is too short, man.",
              "default": "Just write a proper address, will you?" //Special catch all error message
            },
            "description": "Email will be used for evil.",
            required: true
          },

绑定有问题吗?

【问题讨论】:

    标签: javascript jquery angularjs angularjs-directive angular-schema-form


    【解决方案1】:

    您在错误的位置添加了 onChange。它不应该是模式,而是形式。检查这个http://plnkr.co/edit/h02XKqF3Vc6eefTOEN8m?p=preview

     $scope.form = [
            "name",
            "student",
            {
              key: "email",
              onChange: function(modelValue, form) {
                console.log("email changed");
                console.debug(modelValue);
                console.debug(form);
              }
            },
            "title",
            {
              type: "submit",
              title: "Save"
            }
          ];
    

    尽管在您输入有效值之前不会触发电子邮件字段事件。不确定它是否应该这样工作。

    您还缺少 angular-schema-form 标记,因为此问题与该特定库有关。

    BR

    【讨论】:

      【解决方案2】:

      我查看了 sfChanged 指令。可惜……

      我不想花很多时间来绑定一个更改事件。 可能这个工具不严重吧……

      要插入更改事件逻辑,请在您的 html 表单对象上确保:

      ng-model (add to sf-model, sf-schema, sf-form)

      绑定在模型窗体上,例如:

      ng-model="modelForm" (sf-Model="modelForm")

      在您的 HTML 表单对象上确保存在 sf-changed 属性 使用这种语法:

      sf-changed="onChange"

      在 schema 对象上,对于要绑定更改事件的键,写:

      {
        key: "yourkey",
        ...blabla...waouou...
        x-schema-form: {
          onChange: function () { console.log('now it runs'); }
       }  
      }
      

      我调试了 sfChanged 指令,现在你的 change 事件被触发了。

      无法识别您的更改事件单独在表单对象上。

      “模糊选项”个人运行,我发现了这个工具,我哭了“为什么是我?” “为什么这么讨厌?”

      文档有一个大漏洞,祝你有美好的一天。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-06-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-06-28
        相关资源
        最近更新 更多