AngularJS ng-model獲取不到WdatePicker值的解決方案
阿新 • • 發佈:2019-01-25
refs:
1)加一個onChange=""
2)在directive中實現
使用AngularJS directive指令,通過onpicked(選中後觸發)和oncleared(點選清除按鈕觸發)兩個回撥函式來觸發元素的change事件,AngularJS就可以獲取到日期值了,程式碼如下:
var app = angular.module("root",[]);
app.directive('wdatePicker',function(){
return{
restrict:"A",
link:function(scope,element,attr){
element.bind('click',function(){
window.WdatePicker({
onpicked: function(){element.change()},
oncleared:function(){element.change()}
})
});
}
}
});
引用指令wdate-picker指令
<input class="form-control" ng-model="date" wdate-picker placeholder="請輸入時間">
---------------------