我在角形中使用jqxgrid。当您在网格中更改某些内容时,角形不会变脏。我决定绑定到grid cellvaluechaned事件 我将$ setDirty()称为我的角形。有用。但我不想在每个使用表单调用$ setDirty()的地方。你能告诉我怎样才能找到 DOM树中最接近的形式,让它变脏?我想写这段代码一次,并希望它适用于这些表单中有网格的每个表单。谢谢你们。
答案 0 :(得分:0)
您可以创建一个循环遍历其下所有必需html元素的指令,并添加相关事件。
这是一个让你入门的模板:
angular.module("app", []).directive("changeform", function() {
var directive = {
restrict: 'A',
require: 'form',
link: function(scope, element, attrs, ctrl) {
// here you would use element.find() to get the elements
// and then use .on() on the elements with the event
// and then use the ctrl (which is of type FormController)
// to set $dirty [https://docs.angularjs.org/api/ng/type/form.FormController]
}
}
})
然后HTML应该如下所示:
<form name="myForm" changeform> ... </form>