angularjs - How to use angular "element" parent or find methods to get access to the parent form? -


In an angular JS instruction that is on "form input level", a reference to the parent form for admission I want to "submit" event.

Right now, I can inquire and submit the form with ID.

But, I want to get it done by the "Elements" method of finger. But it just will not work.

  Angular Module ('app dot com'). {Return: 'A' is required: '^ form', scope: {error: '= validated field'}, ('valid' field ', [' $ timeout ', function ($ timeout) Link: function (scope, L, ethers, form) {if (document.getElementById ('test')) {var e = Angular.element (document.getElementById ('test')) e.on ('submit', function () {Console.log ('Works!');})}} LPearre ('form'). ('Submit', function () {console.log ('how do i do this?');})}}}}}]);  

Any ideas how?

UPDATE

I have found a solution, sure it is not an elegant:

  // Valid field Angular.element on "submit form" (el [0] .form) .on ('submit', function () {validate ();});  

You can use CSS selectors inside Angular. Element function,

  angular.element ('# myId'), angular.element ('. MyClass')  

With it, when you need Then you can further extend your instructions by using the Form Controller, named $ property:

 : '^ form', link: function (scope, L, etters, form) {... if (form. $ Name) {var domForm = angular.element ("[name =" + form. $ Name + "]") domForm.addClass ('whee'); }}  

Comments