यह स्पष्ट रूप से अद्यतन प्रत्येक दूसरे के साथ आज की तारीख रूप को दर्शाता है Fiddle
में इस उदाहरण पर एक नजर डालें।
जे एस
function Ctrl2($scope,$timeout) {
$scope.format = 'M/d/yy h:mm:ss a';
}
angular.module('time', [])
// Register the 'myCurrentTime' directive factory method.
// We inject $timeout and dateFilter service since the factory method is DI.
.directive('myCurrentTime', function($timeout, dateFilter) {
// return the directive link function. (compile function not needed)
return function(scope, element, attrs) {
var format, // date format
timeoutId; // timeoutId, so that we can cancel the time updates
// used to update the UI
function updateTime() {
element.text(dateFilter(new Date(), format));
}
// watch the expression, and update the UI on change.
scope.$watch(attrs.myCurrentTime, function(value) {
format = value;
updateTime();
});
// schedule update in one second
function updateLater() {
// save the timeoutId for canceling
timeoutId = $timeout(function() {
updateTime(); // update DOM
updateLater(); // schedule another update
}, 1000);
}
// listen on DOM destroy (removal) event, and cancel the next UI update
// to prevent updating time ofter the DOM element was removed.
element.bind('$destroy', function() {
$timeout.cancel(timeoutId);
});
updateLater(); // kick off the UI update process.
}
});
एचटीएमएल
<div ng-app="time">
<div ng-controller="Ctrl2">
Date format: <input ng-model="format"> <hr/>
Current time is: <span my-current-time="format"></span>
</div>
</div>
स्रोत
2013-07-14 17:41:18
यह मेरे मदद की .. सरल समाधान है .. मैं इस जवाब होना चाहिए महसूस – Dinesh
वाह। यह सिम्पे था। हाँ यह जवाब होना चाहिए। – tkarls