/**
* 使用示例
* <input def-laydate type="text" id="id1" ng-model="startTime"/>
*/
app
.directive('defLaydate', function() {
return {
require: '?ngModel',
restrict: 'A',
scope: {
ngModel: '='
},
link: function(scope, element, attr, ngModel) {
var _date = null,_config={};
// 初始化参数
_config = {
elem: '#' + attr.id,
format: attr.format != undefined && attr.format != '' ? attr.format : 'YYYY-MM-DD',
max:attr.hasOwnProperty('maxDate')?attr.maxDate:'',
min:attr.hasOwnProperty('minDate')?attr.minDate:'',
choose: function(data) {
scope.$apply(setViewValue);
},
clear:function(){
ngModel.$setViewValue(null);
}
};
// 初始化
_date= laydate(_config);
// 模型值同步到视图上
ngModel.$render = function() {
element.val(ngModel.$viewValue || '');
};
// 监听元素上的事件
element.on('blur keyup change', function() {
scope.$apply(setViewValue);
});
setViewValue();
// 更新模型上的视图值
function setViewValue() {
var val = element.val();
ngModel.$setViewValue(val);
}
}
}
})
app.directive('defLaydate', function() {
return {
require: '?ngModel',
restrict: 'A',
scope: {
ngModel: '=',
maxDate:'@',
minDate:'@'
},
link: function(scope, element, attr, ngModel) {
var _date = null,_config={};
// 初始化参数
_config = {
elem: '#' + attr.id,
format: attr.format != undefined && attr.format != '' ? attr.format : 'YYYY-MM-DD',
max:attr.hasOwnProperty('maxDate')?attr.maxDate:'',
min:attr.hasOwnProperty('minDate')?attr.minDate:'',
choose: function(data) {
scope.$apply(setViewValue);
},
clear:function(){
ngModel.$setViewValue(null);
}
};
// 初始化
_date= laydate(_config);
// 监听日期最大值
if(attr.hasOwnProperty('maxDate')){
attr.$observe('maxDate', function (val) {
_config.max = val;
})
}
// 监听日期最小值
if(attr.hasOwnProperty('minDate')){
attr.$observe('minDate', function (val) {
_config.min = val;
})
}
// 模型值同步到视图上
ngModel.$render = function() {
element.val(ngModel.$viewValue || '');
};
// 监听元素上的事件
element.on('blur keyup change', function() {
scope.$apply(setViewValue);
});
setViewValue();
// 更新模型上的视图值
function setViewValue() {
var val = element.val();
ngModel.$setViewValue(val);
}
}
}
})
app.directive('ngcLayDate', function($timeout) {
return {
require: '?ngModel',
restrict: 'A',
scope: {
ngModel: '=',
maxDate:'@',
minDate:'@'
},
link: function(scope, element, attr, ngModel) {
var _date = null,_config={};
// 渲染模板完成后执行
$timeout(function(){
// 初始化参数
_config = {
elem: '#' + attr.id,
format: attr.format != undefined && attr.format != '' ? attr.format : 'YYYY-MM-DD',
max:attr.hasOwnProperty('maxDate')?attr.maxDate:'',
min:attr.hasOwnProperty('minDate')?attr.minDate:'',
choose: function(data) {
scope.$apply(setViewValue);
},
clear:function(){
ngModel.$setViewValue(null);
}
};
// 初始化
_date= laydate(_config);
// 监听日期最大值
if(attr.hasOwnProperty('maxDate')){
attr.$observe('maxDate', function (val) {
_config.max = val;
})
}
// 监听日期最小值
if(attr.hasOwnProperty('minDate')){
attr.$observe('minDate', function (val) {
_config.min = val;
})
}
// 模型值同步到视图上
ngModel.$render = function() {
element.val(ngModel.$viewValue || '');
};
// 监听元素上的事件
element.on('blur keyup change', function() {
scope.$apply(setViewValue);
});
setViewValue();
// 更新模型上的视图值
function setViewValue() {
var val = element.val();
ngModel.$setViewValue(val);
}
},0);
}
};
})
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有