2014-09-25 3 views
1

나는 Angular Date documentation here을 발견했으며 yyyy 필터로 충분하다고 생각했지만 실제 날짜에는 여전히 첨부되어 있습니다.각도로 4 자리 연도를 표시하는 방법은 무엇입니까?

내 HTML : 바닥 글에 대한

<p class="footer_copy">&copy; {{ footer.date | date : yyyy }} AT&amp;T</p> 

내 각도 지침, 함수와 데이트를 만들 : 그것은 & AT 2014년 9월 24일 © 을 뱉어 그러나 지금

// Directive for Footer 
app.directive('appFooter', function() { 
    return { 
     restrict: 'E', 
     templateUrl: 'templates/app-footer.html', 
     controller: function(){ 
      this.date = Date.now(); 
     }, 
     controllerAs:'footer' 
    }; 
}); 

을 T

그냥 작성하고 싶습니다. © 2014 AT & T

답변

3

당신은 문자열로 형식을 전달하는 데 사용할 필요가

var app = angular.module('my-app', [], function() {}) 
 

 
app.directive('appFooter', function() { 
 
    return { 
 
     restrict: 'E', 
 
     template: '<p class="footer_copy">&copy; {{ footer.date | date:"yyyy" }} AT&amp;T</p>', 
 
     controller: function(){ 
 
      this.date = Date.now(); 
 
     }, 
 
     controllerAs:'footer' 
 
    }; 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> 
 
<div ng-app="my-app"> 
 
    <app-footer></app-footer> 
 
</div>
또 다른 옵션은 내가 지침에 해당 컨트롤러를 결합 할 수 있습니다
var app = angular.module('my-app', [], function() {}) 
 

 
app.directive('appFooter', function() { 
 
    return { 
 
    restrict: 'E', 
 
    template: '<p class="footer_copy">&copy; {{ footer.date | date:footer.dateFormat }} AT&amp;T</p>', 
 
    controller: function() { 
 
     this.date = Date.now(); 
 
     this.dateFormat = 'yyyy' 
 
    }, 
 
    controllerAs: 'footer' 
 
    }; 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> 
 
<div ng-app="my-app"> 
 
    <app-footer></app-footer> 
 
</div>

+1

같은 변수로 형식을 전달하는 것입니다 옳은? 전체 컨트롤러를 낭비하는 것만으로도 날짜를 낭비하지 않아도됩니다. 나는 그들이 지금 가지고있는 것과 어떻게 결합 될 것인가? –

+1

@LonGaban 예 .. 할 수 있어요 –

+0

아아, 내 yyyy 주위에 따옴표가 누락되었습니다. 'yyyy'감사합니다. 4 분 –

관련 문제