title: Dynamically add $watch
body: <p>I have a JSON dataset that each row includes an input value, a small block of JavaScript code used to calculate and a subtotal value that is the result of the input value after an eval() preforms the calculation.  The dataset will contain one or more rows.  Each input will be repeated onto the page in HTML and a sum of the subtotals will be shown to the user as a total value along with each separate subtotal value.</p>
  
  <p>I tried to use $watch and add one for each row in the repeater but I can't seem to get them to fire as the user changes the input value. </p>
  
  <p>I have created my first <a href="http://plnkr.co/edit/MNTEeY12UDP0rERn0w6s" rel="nofollow">Sample_Plunker </a> to demonstrate what I'm trying to achieve with no success.  </p>
  
  <p>Not sure if I should also be posting the code here or not but any help would be greatly appreciated.</p>
  
  <p>Basically my HTML: </p>
  
  <pre><code>&lt;div ng-controller="MainCtrl as MainCtrl" ng-init="MainCtrl.init()"&gt;
      &lt;div ng-repeat="rule in MainCtrl.myCode"&gt;
  
          Input_{{$index}}: &lt;input ng-model="rule.inpValue" type="number" /&gt;
          &lt;!-- the following needs to reflect the result after eval() of myCode[?].code from JSON below --&gt;
          Subtotal: {{rule.nSubTotal}}
          &lt;br /&gt;
      &lt;/div&gt;
      &lt;br /&gt;
  
      &lt;!-- the following should be a sum of all values above --&gt;
      Total: {{MainCtrl.nTotal}}
  
  &lt;/div&gt;
  </code></pre>
  
  <p>This is my sample data and $watch that is not responding:</p>
  
  <pre><code>app.controller('MainCtrl', function($scope) {
      var _this = this;
      _this.nTotal = 0;
      // sample js code tht will be execuited later
      _this.myCode = [{
          "code": "_this.myCode.inpValue +2",
          "inpValue": 0,
          "nSubTotal": 0
      }, {
          "code": "_this.myCode.inpValue*3",
          "inpValue": 0,
          "nSubTotal": 0
      }, {
          "code": "_this.myCode.inpValue/5",
          "inpValue": 0,
          "nSubTotal": 0
      }];
  
      this.init = function() {
          $scope.$watch('MainCtrl.myCode[i].inpValue', function() {
              // debugger;
  
              // assuming if watch would fire, subtotal = eval( input ) 
              _this.nSubTotal = eval(_this.myCode[i].code);
  
              // I would also keep a running total at this point
              _this.nTotal = _this.nTotal + _this.myCode[i].nSubTotal;
          });
      }; //end init()
  });
  </code></pre>