[英]AngularJS Error: Cannot use 'in' operator to search for '$ctrl' in
[英]AngularJS custom directive and ctrl, throws error if: the method of ctrl is the same as name of ctrl
我還是AngularJS的新手,所以這是我必須解決的問題:
我制作了一個自定義提交指令,只有在有效時才提交表單。 它可以像這樣使用:
<form novalidate mm-submit="mySubmitMethod()">
一切正常,直到我嘗試使用register
方法的RegisterCtrl
; 提交時,該指令拋出以下錯誤:
TypeError: object is not a function at ajax.googleapis.com/ajax/libs/angularjs/1.2.0-rc.3/angular.js:9068:15
如果該方法被命名為register2
或其他東西一切正常。
這是一個帶有演示和源代碼的工作插件 。
因為您的表單名稱是register
,它將FormController綁定到父作用域上的register
屬性。 如果你的指令中有console.log(scope.register)
,你會在那里看到FormController。 如果您不創建任何隔離范圍,則需要將提交函數定義為不同的或更改您的表單名稱以防止此沖突。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.