我的控制器中有这样的代码:
var forms = $('form'); // my selector is a bit more complex.
var form = forms[0];
这给了我表格。从这个我怎么得到FormController,以便我可以查看$ pristine,$ invalid等属性?
var formController = // how to get this from form?
var ispristine = formController.$pristine;
我实际上有多个子表单,我必须得到它们的原始状态。
由于
答案 0 :(得分:0)
我认为你可以这样做来获取表单的“FormController”属性:
// Get hold of the form in your DOM
var forms = $('form');
var form = forms[0];
// Get hold of the form's scope object, which is injected with an object containing these properties.
// Note that 'formName is the name of the form element in html. (<form name='formName'>....</form>
var formScope = $(form).scope().formName;
var ispristine = formScope.$pristine;
请注意,仅当表单元素具有名称属性时才有效!