cornstar94
cornstar94

Reputation: 89

How do I bind the value on the button to my ng-model?

I am trying to bind the value on the button to my ng-model, but it doesn't seem to work. Does anyone have any suggestions on what I should do?

I am using the datepicker from https://github.com/rajeshwarpatlolla/ionic-datepicker

<div class="col">
  <label class="item item-input small">
   Start Date: <br> 

    <ionic-datepicker input-obj="datepickerObject">        
      <input type="button" ng-model="vm.newObject.startDate" value="
        {{datepickerObject.inputDate|date:'dd - MMM - yy'}}"> 
    </ionic-datepicker>

   </label>
</div> 

Upvotes: 1

Views: 1328

Answers (2)

Praveen
Praveen

Reputation: 195

we can use button element with {{}} to display the data returned

<ionic-datepicker input-obj="datepickerObject"> 

    <button type="button">{{datepickerObject.inputDate|date:'dd - MMM - yy'}} 
</button> 

</ionic-datepicker>

Upvotes: 0

Shashank Agrawal
Shashank Agrawal

Reputation: 25797

Remove the ng-model from the button and you can modify your datepickerObject object like this:

$scope.datepickerObject = {
    // ... Other keys & values
    callback: function(value) {
        $scope.newObject.startDate = value;
        // or use the "vm" variable as you are using (not sure how you are using the scope)
        // vm.newObject.startDate = value; 
    }
};

From the documentation link you mentioned:

r) callback(Mandatory) : This the callback function, which will get the selected date in to the controller. You can define this function as follows.

Upvotes: 1

Related Questions