【发布时间】:2013-12-26 17:33:38
【问题描述】:
我正在阅读有关指令的 Angular 文档:http://docs.angularjs.org/guide/directive
页面上的一个例子(完整的工作例子在这里http://jsbin.com/osOQOYag/3/edit?html,js,output
angular.module('docsTimeDirective', [])
.controller('Ctrl2', function($scope) {
$scope.format = 'M/d/yy h:mm:ss a';
})
.directive('myCurrentTime', function($interval, dateFilter) {
function link(scope, element, attrs) {
var format,
timeoutId;
function updateTime() {
element.text(dateFilter(new Date(), format));
}
scope.$watch(attrs.myCurrentTime, function(value) {
format = value;
updateTime();
});
element.on('$destroy', function() {
$interval.cancel(timeoutId);
});
// start the UI update process; save the timeoutId for canceling
timeoutId = $interval(function() {
updateTime(); // update DOM
}, 1000);
}
return {
link: link
};
});
上线:
.directive('myCurrentTime', function($interval, dateFilter) {
我终其一生都找不到关于 .directive 原型的任何信息,也无法在任何地方找到关于 dateFilter 的任何文档。另外,我知道 dateFilter 可以在 AngularJS 的未缩小版本中找到(尽管名称在缩小版本中消失了)。谁能提供一些指导(可能还有链接)来解释有关 dateFilter 和类似功能的更多信息?
【问题讨论】:
-
我同意,如果文档中没有包含这种方法,他们不应该使用这种方法。
标签: angularjs angularjs-directive datefilter