如何将按钮上的值绑定到ng-model?

时间:2015-12-30 07:23:03

标签: angularjs datepicker ionic-framework ionic

我正在尝试将按钮上的值绑定到ng-model,但它似乎无法正常工作。有没有人对我该做什么有任何建议?

我正在使用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> 

2 个答案:

答案 0 :(得分:1)

ng-model中移除button,您可以像这样修改datepickerObject对象:

$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; 
    }
};

从您提到的文档链接中:

  

r)回调(强制):这是回调函数,它将得到   所选日期到控制器。您可以定义此功能   如下。

答案 1 :(得分:0)

我们可以使用带有{{}}的按钮元素来显示返回的数据

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

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

</ionic-datepicker>