2015-11-17 22 views
1

使用Angular Formly,我使​​用'hideExpression'隱藏基於另一個字段的模型值的字段。這按預期工作。但是,我需要在隱藏字段模型值被隱藏時重置它。這怎麼能在Angular-Formly中完成?是否有某種類型的活動可以掛鉤?Angular-Formly:隱藏時重置字段模型

回答

1

可以使用hideExpression回調並設置模式返回值true或false

{ 
      key: 'model_key', 
      type: 'input', 
      templateOptions: { 
       label: 'Your label' 
      }, 
      hideExpression: function ($viewValue, $modelValue, scope) { 
       var hide = true; // replace true with your condition 
       if (hide) { 
        vm.model.model_key = ''; 
       } 
       return hide; 
      } 
     } 
+0

嗨Zohaib之前,當你讀到這(1年期和2個月後)。你能告訴我嗎?我用條件代替真實。比方說,在這個bin http://jsbin.com/tifizogizu/1/edit?js,output;但它不像我預期的那樣運作,你能幫我嗎? –

+0

如果你想使用表達式,那麼不要使用函數。 –

+0

@LexHartman使用'hideExpression:「!model.name」'如果你想使用函數,然後返回truthy值來隱藏。 –