Use the date filter.
By passing MMM
as parameter, the output will be the name of the shortened month (Jan - Dec). Using MMMM
the output will be the month name in full (January - December).
It is also possible to use the date
direct filter on the controller, injecting $filter
.
In order for the names to be shown in Portuguese, you will need to have the internationalization script referenced in the project.
Complete example:
var app = angular.module('dt-app', []);
app.controller('testCtrl', function($scope, $filter){
$scope.data = new Date();
$scope.dataFormatada = $filter('date')($scope.data, 'MMMM');
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/angular-i18n/1.6.4/angular-locale_pt-br.min.js"></script>
<div ng-app="dt-app">
<div ng-controller="testCtrl">
<div>
<h4>Formatando direto na view</h4>
{{ data | date: 'MMM'}}<br>
{{ data | date: 'MMMM'}}
</div>
<hr>
<div id="dt-ctrl">
<h4>Formatando no controller:</h4>
{{ dataFormatada }}
</div>
</div>
</div>