【问题标题】:I am not able to use 'ng-change' in one of my custom AngularJS directives我无法在我的自定义 AngularJS 指令之一中使用“ng-change”
【发布时间】:2017-12-27 08:31:04
【问题描述】:

父页面.html

<records-grid-column ng-change="validateData()" ng-model="name">                     
        {{item.name}}  </records-grid-column>  

指令控制器

   directive = {
    restrict: 'E',
    controller: ABCD,
    scope: {
        ngModel:'=',
        ngChange:'&',
        class:'='
    },
    transclude: true,
    replace: true,
    template: '<td class></td>'
};

return directive;

编辑 - 我将 Modal 更改为模型,但我仍然遇到同样的错误......

函数 validateData() 在父页面上,但在页面加载时我收到此错误 - 'Error: [Error] [$compile:ctreq] Controller 'ngModel', required by directive 'ngChange', can't be found!'

我尝试了一切,但无法解决问题,总的来说,我只是想调用一个函数来验证编辑后的数据,为此我正在使用“ngChange”。 请让我知道我错在哪里,非常感谢您的帮助:)

【问题讨论】:

  • 参见。 modalmodel
  • 我改了,但还是一样的错误 - '错误:[错误] [$compile:ctreq] 控制器'ngModel',指令'ngChange'需要,找不到!'
  • 你能给出更完整的代码示例吗?也许在 plunkr 上?

标签: angularjs angularjs-scope angularjs-ng-change custom-directive


【解决方案1】:

改变

来自

  scope: {
        ngModal:'=',
        ngChange:'&',
        class:'='
    }

scope: {
    ngModel:'=',
    ngChange:'&',
    class:'='
}

【讨论】:

  • 我改了,但还是一样的错误 - '错误:[错误] [$compile:ctreq] 控制器'ngModel',指令'ngChange'需要,找不到!'
猜你喜欢
  • 2015-09-25
  • 1970-01-01
  • 2019-04-16
  • 2020-10-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-01-24
  • 1970-01-01
相关资源
最近更新 更多