您可以使用ng-model
與ng-blur
和特定方法(changeDate()
)返回您需要的時候焦點丟失:
HTML:
<input type="text" ng-model="textInput" ng-blur="changeDate()">
控制器:
$scope.changeDate = function() {
$scope.textInput = $scope.textInput + '/12/2016';
}
當然,你應該添加一個更好的方式來計算日期在changeDate
我做了快只是爲了給你一個想法。
編輯:對不起它NG-模糊,當你失去焦點
要使用它作爲指令:
JS:
app.directive('myInput', function() {
return {
restrict: 'E',
replace: 'true',
scope: {
inputdata: '='
},
template: '<input type="text" ng-model="inputdata" ng-blur="changeDate()">',
controller: function ($scope) {
$scope.changeDate = function() {
$scope.inputdata = $scope.inputdata + '/12/2016';
}
}
};
});
HTML:
<my-input inputdata="textInput"></my-input>
不輸入字段是一個日期選擇器? –
然後你可以使用ng-change – GraveyardQueen