title: Two-way binding to input component with AngularJS(1.6)
body: <p>I have a parent component receives data from the server, and has to create a specific (and different) object that will be sent to the server any time the info is updated.
  Parent controller:</p>
  
  <pre><code>function ParentController() {
    this.$onInit = () =&gt; {
    // get user data from server
      this.userDataObject = {
        userInformation: {
          firstName: response.data.firstName,
          lastName: response.data.lasName,
        },
        contactInformation: {
          email: response.data.email,
          phone: response.data.phone
        }
      }
    }
      this.saveToDB = () =&gt; {
          httpPostCall(this.userDataObject);
      }
  }
  </code></pre>
  
  <p>Each property of data is passed to a child component which is essentially an input element (with complex display logic, hence separated into a different component).
  Parent template:</p>
  
  <pre><code>&lt;parent-component&gt;
      &lt;child-component save-value="$ctrl.saveToDB()"
          field-value="$ctrl.userDataObject.userInformation.firstName"&gt;
      &lt;/child-component&gt;
  &lt;/parent-component&gt;
  </code></pre>
  
  <p>The child is an input field with two-way data binding to relevant property on <code>userDataObject</code>:</p>
  
  <pre><code>bindings: {
      fieldValue: '=',
      saveValue: '&amp;'
  }
  </code></pre>
  
  <p>And then the child binds the field value to input value via NgModel (using placeholder text if field value is empty). The value binding to the model works fine, so parent component data changes when the user provides input:</p>
  
  <pre><code>&lt;div&gt;
      &lt;input ng-model="$ctrl.fieldValue"&gt;
      &lt;button ng-click="$ctrl.saveValue()"&gt;OK&lt;/button&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>This works in that a change to the input changes <code>buyerDataObject</code> and then on saving updates the database.</p>
  
  <p>However, it also works if no change has been made to <code>fieldValue</code>, so if the user clicks the button without changing the value, it will still save to the DB. I want to find a way to determine whether the value has changed.</p>
  
  <p>I've tried saving the value of <code>fieldValue</code> to a local variable in child component in <code>$onInit</code>, but it returns undefined. I can watch the variable and save the initial value, but would rather avoid adding watchers to the mix. It feels like there should be a more straightforward way to solve this problem.</p>