在我的控制器中有这样的代码:
var forms = $('form'); // my selector is a bit more complex.
var form = forms[0];
这给了我这个表单。从这我怎么得到的FormController,以便我可以检查属性,如$质朴,$无效等?
var formController = // how to get this from form?
var ispristine = formController.$pristine;
我实际上有多个子窗体,我必须获得它们的原始状态。
谢谢
我认为你可以这样做来获得窗体的"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;
注意,这只在表单元素有name属性时起作用!