programing

dateFilter란 무엇이며 자세한 내용은 어디에서 확인할 수 있습니까?

jooyons 2023. 11. 6. 21:48
반응형

dateFilter란 무엇이며 자세한 내용은 어디에서 확인할 수 있습니까?

지시사항에 대한 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 prototype에 대한 정보를 찾을 수 없고 dateFilter에 대한 문서도 찾을 수 없습니다.또한, AngularJS의 Unminized 버전에서 dateFilter가 발견된다는 것을 알고 있습니다(minized 버전에서는 이름이 사라지지만).dateFilter 및 유사한 기능에 대해 설명하는 몇 가지 지침(및 링크)을 제공할 수 있는 사람이 있습니까?

날짜 필터 문서는 여기에 있습니다.

다음은 필터 주입을 설명하는 문서의 일부입니다. http://code.angularjs.org/1.2.5/docs/guide/filter#using-filters-in-controllers-and-services

필터는 일반적으로 뷰 표현식에 사용됩니다({{myDate | date:'short'}}), 하지만 JS 코드에서도 사용할 수 있습니다.필터는 문자열을 추가하여 주입합니다.Filter필터 이름(예:date->dateFilter).

app.controller('MyCtrl', function($scope, dateFilter, lowercaseFilter){
  $scope.myDate = new Date();
  $scope.myDateFormatted = dateFilter($scope.myDate, 'shortDate');

  $scope.myString = 'Some String';
  $scope.myStringLowerCased = lowercaseFilter($scope.myString);
});

PLUNKER

언급URL : https://stackoverflow.com/questions/20788773/what-is-datefilter-and-where-can-i-find-out-more-about-it

반응형