javascript - 为什么 onchange 事件不会在 angular js 中触发?

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

我正在从 json 制作一个表格。我正在使用 angular-schema-form 并在 tv4.js 中依赖。我从中学习 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
          },

绑定(bind)有问题吗?

最佳答案

您在错误的位置添加了 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

关于javascript - 为什么 onchange 事件不会在 angular js 中触发?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25336417/

相关文章:

javascript - 为表格单元格外化 ng 类

javascript - 从我的 .json 文件/第一次 js Node 用户获取未定义的值

javascript - 我的验证不适用于 textarea

javascript - 嵌套每个循环导致问题

jquery - -webkit-animation/keyframes 不能与 -webkit-filter blur 一起很好地播放

javascript - 使用 ajax 和 Angular 填充选择选项

javascript - 解析 html 字符串 Windows 8 javascript 应用程序

javascript - 如何使用 Javascript 加载 NSTableView 以实现自动化

javascript - 对各种 webpack shimming 方法的困惑

javascript - Angularjs - 指令上的 ng-disabled 执行顺序