我有一个表单,试图将日期选择器对象转换为指令。我能够将数据输入到输入中,但是没有将数据与传递给它的作用域变量绑定在一起。这是我的代码。
看法:
<ng-date-picker id-attr="lastRedemptionDate" ng-model="spr.lastRedemptionDate"></ng-date-picker>
指示:
myApp.directive('ngDatePicker', function() {
return {
restrict: 'AEC',
templateUrl: 'assets/angular/directives/datePicker.html',
replace: true,
scope: {
objID: '@idAttr',
personName: "=ngModel"
},
link: function($scope, elem, attrs, controllerInstance) {
$scope.$apply($scope.method());
$('.datepicker').datepicker({
format: 'm/d/yyyy',
autoclose: true
});
console.log($scope);
}
}
})
指令模板:
<div class='input-group input-append date'>
<input type='text' class="form-control datepicker" id="{{ objID }}" value="{{ personName }}" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
任何帮助将不胜感激。
使用ngModel指令将模型绑定到输入而不是value属性:
<div class='input-group input-append date'>
<input type='text' class="form-control datepicker" ng-model="personName" id="{{ objID }}" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句