是否可以在angularJS中观看日期?我有一个包含日期的ng模型,我想观看它,所以当它改变月份,年份或日期时,我会收到通知。
scope.$watch('ngModel',function(newVal){
console.log(newVal);
},true);
我有一个控制器,我将日期对象赋给指令。现在我想看那个约会对象。
module.directive('Datepicker',function(){
return {
restrict:'E',
scope:{
ngModel:"="
},
link: function(scope, element, attrs) {
//..other code here
scope.$watch('ngModel', function(newVal) {
console.log(ngModel);
}, true);
}
}
});
我相信你在指令中,那么你应该使用attrs.ngModel
而不是ngModel
仅仅使用它,它应该在指令的链接/编译函数中
代码
app.directive('myDirective', function() {
return {
'restrict': 'E',
scope: { ngModel: '='},
link: function(scope, element, attrs, ngModel) {
//..other code here
scope.$watch('$parent.'+ attrs.ngModel, function(newVal) {
console.log(newVal);
}, true);
}
};
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句