假設我有一個擴展輸入類型的自定義角型表單類型。 讓我們叫它用戶。如何在驗證時將複雜對象添加到每個角型模型的模型中?
之前的形式得到填補模型= {}。
一旦其填充和有效的,我想有這樣的結果
model = {
user:{
name:"TestName" //The value of the input
someCustomData: "Not part of the form"
someMoreMetaData: "Also not part of the from"
}
}
具有附在生成的模型的任意元數據,一旦用戶輸入有效的名稱。因此,創建一個「用戶專用模型」
所以基本上,我想我的驗證功能,結果推到模型。
我怎麼會接近這一點,關鍵必須被綁定到一個對象,一旦確認返回true,將只存在的屬性。
{
key: //what do I bind to?
type: 'USER',
templateOptions: {
required: true,
type: 'text'
},
validators:{
isValid: function($viewValue, $modelValue, scope){
var value = $modelValue || $viewValue;
if (validateName(value)){
scope.model.user = { name: viewValue, date:....}
return true;
}
}
}
}
如果可能的話,請輕推我在正確的direction..Still漂亮的新手。
你能分享一些代碼,你目前有什麼? –