javascript - How to access form object with two-way-binding in angular directive without isolated scope -


as titled, given following simple example:

<form name="myform">   <button my-directive-test="myform">hello</button> </form>  app.directive('my-directive-test', function() {  return {    restrict:'a',    link: function(scope, element, attrs) {        // how scope.myform.$submitted, scope.myform.$errors without isolated scope?    })  }; }); 

currently have been doing is:

<form name="myform">   <button my-directive-test="{{myform.$submitted}}">hello</button> </form>  app.directive('my-directive-test', function() {  return {    restrict:'a',    link: function(scope, element, attrs) {      scope.formsubmitted = scope.$eval(attrs.mydirectivetest);      if (scope.formsubmitted) {      } else {      }    })  }; }); 

but achieve is:

<form name="myform">   <button my-directive-test="myform">hello</button> </form>  app.directive('my-directive-test', function() {  return {    restrict:'a',    link: function(scope, element, attrs) {      if (scope.myform.$submitted) {      } else {      }    })  }; }); 

but far haven't found way bind form object in directive.

when not using isolated scope, directive scope same "parent" element's scope. work:

<form name="myform">   <button my-directive-test="myform">hello</button> </form>  app.directive('mydirectivetest', function() {  return {    restrict:'a',    link: function(scope, element, attrs) {      if (scope[attrs.mydirectivetest].$submitted) {      } else {      }    })  }; }); 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -