0

Lets say that I have a form with one dropdown with options foo, bar and 3 input fields: input1, input2 and input3. All formfields ar binded to a $scope object.

I would like to make a setup where if the user in the dropdown selects:

  • foo, then $watch listens to changes in input1 and input2 but not input3.
  • bar, then $watch listens to changes in input3 but not input1 and input2.

On change detection, depending which option was selected in the dropdown, a function in the controller should be called: function foo () or function bar ().

And to complicate things even more the called function should check if the according input fields are valid. If yes, then do some bussiness logic with the input field values and store the result on a $scope.

Martin
  • 1
  • 1
    It's usually expected that you show what you have tried, and describe where your stuck. To get you started: you can call $scope.$watch() for the initial setup. When you call `$watch()` the return value is a de-registration function that removes the watcher. Use ng-change on the select (or `$watch()` the model bound to the select), and when the value changes remove the old watcher and add the new one. – Sunil D. Feb 11 '15 at 20:16
  • Sunil, I would, but Im stuck right at the begining by dinamicly setting which inputs to watch, so theres nothing to show. – Martin Feb 11 '15 at 21:02

0 Answers0