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
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.