請了一個月的名稱簡單的指令。
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body>
<div ng-app="myApp" ng-controller="myCtrl">
<any ng-repeat="x in item">
<my-dir myindex="x.ReviewMonth"></my-dir>
</any>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope)
{
$scope.item =
[
{
ReviewMonth:"9"
},
{
ReviewMonth:"2"
},
{
ReviewMonth:"3"
},
{
ReviewMonth:"4"
},
{
ReviewMonth:"5"
},
{
ReviewMonth:"6"
},
{
ReviewMonth:"7"
},
{
ReviewMonth:"7"
}
]
});
app.directive('myDir', function()
{
return {
restrict: 'E',
scope: {
myindex: '='
},
template:'<div>{{myindex}}</div>',
link: function(scope, element, attrs)
{
var months = ["jan","feb","mar","apr","may","june","july","aug","sep","oct","nov","dec"];
scope.myindex = months[scope.myindex];
}
};
})
</script>
</body>
</html>
問題是,當你嘗試使用NG-重複權發生的呢? –
是的。我正在使用'ng-repeat'。 –
檢查此[link](http://stackoverflow.com/questions/31274581/get-month-name-from-two-digit-month-number)是否有幫助。 – anpsmn