【发布时间】:2012-09-03 08:57:58
【问题描述】:
我正在尝试在使用 angularJs 指令时添加动态添加属性 我想在表单中动态添加html标签
我的看法:
<div ng-show="edit_tasks">
<edittask-form><edittask-form>
</div>
我的表单 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>
}
我的指令
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;
};
}
}
});
如何添加<input type="text" name="xyz" />
形式上
提前考虑
【问题讨论】:
-
不清楚你的意思是这个。你想把这个输入放在哪里?为什么不能直接放在html中?您是指无法动态设置输入上的名称属性的事实吗?
标签: javascript html ruby-on-rails-3 angularjs