Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am trying to add Dynamic add attribute in using angularJs Directive I want to add html tag in form dynamically

My view :

<div ng-show="edit_tasks">   
   <edittask-form><edittask-form> 
</div>

My Form Html

{
<div>
  <form ng-submit="submitFrom()" csrf-tokenized>
    Task Name<input type="text" placeholder="Name" ng-model="newtask.name" required />
    Task Description<input type="text" placeholder="Description" ng-model="newtask.description" required />
    Start Date <input type="text" placeholder="Start date" ng-model="newtask.start_date" required />
    Start Date <input type="text" placeholder="End date" ng-model="newtask.end_date" required />
    <input type="submit" value="submit" />
  </form>
</div>
}

My Directives

module.directive("edittaskForm", function() {
  return {
    restrict: "E",
    templateUrl: "<%=asset_path 'tasks/task_form.html' %>",
    controller: tasksCtrl,
    replace: false,
    link: function(scope, elt, attrs, controller) {
          scope.form = elt.find("form");
          console.log(scope.form);

          scope.taskEdit = function(task) {
            scope.task =  task;
            scope.show_tasks = false;
            scope.edit_tasks = true;
            scope.newtask = task;
          };
        }
  }
});

How Can I add <input type="text" name="xyz" /> in form

Thk's in Advance

share|improve this question
    
It is not clear that you mean by this. Where do you want to put this input? Why can it not be placed straight in the html? Are you referring to the fact that the name attribute on inputs cannot be set dynamically? –  Pete BD Oct 18 '12 at 5:44

1 Answer 1

you can do that in the template simply by using ngShow but if you want to do it in your directive i guess you cant do that in link function because it does not support html transforms as i know, i guess you should try to do it in compile function, you can read more about it here.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.