2016-08-22 57 views
0

的的FormController我有這樣的代碼在我的控制器:獲得一個形式

var forms = $('form'); // my selector is a bit more complex. 
var form = forms[0]; 

這使我的形式。從這我怎麼弄到FormController,以便我可以檢查像$ pristine,$無效等屬性?

var formController = // how to get this from form? 
var ispristine = formController.$pristine; 

我實際上有多個子窗體,我必須得到它們的原始狀態。

感謝

回答

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; 

請注意,這隻有當表單元素具有名稱屬性!