最初当我加载它工作正常,但是当我更改模板URl中的值为ng-model scope.value在我的链接中是未定义的。我正在为datepicker bootstrap angularjs制作指令。
dateTime .directive("DatePicker", function(){
return {
restrict: "E",
transclude: true,
require: "ngModel",
scope:{
ngModel: "=",
dateOptions: "=",
opened: "="
},
link: function($scope, element, attrs, datepickerModel) {
$scope.open = function(event){
event.preventDefault();
event.stopPropagation();
$scope.opened = true;
};
$scope.myModel = new Date();
datepickerModel.$setViewValue($scope.myModel);
$scope.$watch('myModel',function(){
console.log("value changed"+$scope.myModel);
datepickerModel.$setViewValue($scope.myModel);
console.log($scope.myModel);
})
template: ' <input type="date" class="form-control" datepicker-popup="{{format}}" ng-model="myModel" is-open="opened" min-date="minDate" max-date="'2015-06-22'" datepicker-options="dateOptions" date-disabled="disabled(date, mode)" ng-required="true" close-text="Close" />'
}
})