title: Set model value programmatically in Angular.js
body: <p>I'm an author of <a href="https://github.com/betsol/angular-input-modified" rel="nofollow">angular-input-modified</a> directive.</p>
  
  <p>This directive is used to track model's value and allows to check whether the value was modified and also provides <code>reset()</code> function to change value back to the initial state.</p>
  
  <p>Right now, model's initial value is stored in the <code>ngModelController.masterValue</code> property and <code>ngModelController.reset()</code> function is provided. Please see <a href="https://github.com/betsol/angular-input-modified/blob/master/src/directive/ngModel.js#L151-L160" rel="nofollow">the implementation</a>.</p>
  
  <p>I'm using the following statement: <code>eval('$scope.' + modelPath + ' = modelCtrl.masterValue;');</code> in order to revert value back to it's initial state. <code>modelPath</code> here is actually a value of <code>ng-model</code> attribute. This was developed a way back and I don't like this approach, cause <code>ng-model</code> value can be a complex one and also nested scopes will break this functionality.</p>
  
  <p>What is the best way to refactor this statement? How do I update model's value directly through the ngModel controller's interface?</p>