的UI我有type="time"
一個input
標籤如下INPUT TYPE =「時間」屬性值的結合不更新具有角
<input type='time' id='from' ng-model='data.hall.occupancy.timeRange.from' datify value="{{data.hall.occupancy.timeRange.from | propertime}}"/>
在過濾器和指令是如下
app.directive('datify',function(){
return {
require:'ngModel',
link:function(scope,element,attrs,modelCtrl){
modelCtrl.$parsers.push(function(inputValue){
var times = inputValue.split(":");
var hours = times[0];
var mins = times[1];
var currentDate = new Date();
var outputDate = new Date(currentDate.getFullYear(),currentDate.getMonth(),currentDate.getDate(),hours,mins);
return outputDate.toString();
});
}
};
});
app.filter('propertime',function(){
return function(timeStamp){
if(timeStamp){
var dateObj = new Date(timeStamp.toString());
var date = dateObj.getDate();
var month = dateObj.getMonth()+1;
var year = dateObj.getFullYear();
var hours = (0+ dateObj.getHours().toString()).slice(-2);
var minutes = (0+ dateObj.getMinutes().toString()).slice(-2);
return hours+":"+minutes;//+" "+date+"/"+month+"/"+year;
}
}
});
鏈接到我的plnkr:http://plnkr.co/edit/G4G5V62Y70IBvXUXdvQT?p=preview
input
標記的value
屬性在DOM中正確更新,但確實不會影響用戶界面。但是,更新UI中的時間,更新DOM中的value
屬性。有人能告訴我這裏發生了什麼嗎?
注:我使用的瀏覽器(Firefox中顯示輸入型=「時間」作爲一個普通的文本輸入)
當我更改模型時,它不更新UI。點擊更改按鈕,你會明白我的意思。這是爲什麼? –
按下更改按鈕,您會期望什麼? –
是否切換到從? –