forms - How to use dynamic input name inside of directive -


i'm trying implement directive implements a complex input type form. achieve this, ng-model (for binding value) , name (for registering form validating) have set accordingly. while ng-model works should, can't find way set name dynamically.

see plunker here

.directive('mydirective', function() {   return {     template: '<div class="morestuff"><input name="{{name}}" ng-model="ngmodel"></div>',     restrict: 'e',     replace: true,     scope: {       name: '=',       ngmodel: '='     }   }; 

when use inside form like

<form name="myform">   <input type="text" ng-model="value1" name="name1">   <my-directive name="name2" ng-model="value2"></my-directive> </form> 

it results in 3 entries myform:

{   "name1": {},   "{{name}}": {},   "name2": {} } 

so questions:

  1. how implement desired behaviour?
  2. why there entry my-directive element? shouldn't have been removed due replace: true?

yo, should use ng-attr-name

here updated version:

http://jsfiddle.net/l99az/1/

for template:

 <div class="morestuff">       <input type="text" data-ng-attr-name="{{name}}" ng-model="ngmodel"/>       {{name}}  </div> 

you try play "terminal" property of directive clear output of form.

e.g:

http://plnkr.co/edit/z9jf30kscoktm6vehzwv?p=preview


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

inno setup - TLabel or TNewStaticText - change .Font.Style on Focus like Cursor changes with .Cursor -