AngularJS 国际化
AngularJS支持内置的国际化功能,用于三种类型的过滤器:货币、日期和数字。我们只需要根据国家的地区设置相应的javascript即可。默认情况下,它会考虑浏览器的地区设置。例如,对于丹麦地区,可以使用以下脚本-
<script src = "https://code.angularjs.org/1.2.5/i18n/angular-locale_da-dk.js">
</script>
丹麦语区域设置的示例
testAngularJS.htm
<html>
<head>
<title>Angular JS Forms</title>
</head>
<body>
<h2>AngularJS Sample Application</h2>
<div ng-app = "mainApp" ng-controller = "StudentController">
{{fees | currency }} <br/><br/>
{{admissiondate | date }} <br/><br/>
{{rollno | number }}
</div>
<script src = "https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js">
</script>
<script src = "https://code.angularjs.org/1.3.14/i18n/angular-locale_da-dk.js">
</script>
<script>
var mainApp = angular.module("mainApp", []);
mainApp.controller('StudentController', function(scope) {scope.fees = 100;
scope.admissiondate = new Date();scope.rollno = 123.45;
});
</script>
</body>
</html>
输出
在Web浏览器中打开文件 testAngularJS.htm 并查看结果。
使用浏览器区域设置的示例
testAngularJS.htm
<html>
<head>
<title>Angular JS Forms</title>
</head>
<body>
<h2>AngularJS Sample Application</h2>
<div ng-app = "mainApp" ng-controller = "StudentController">
{{fees | currency }} <br/><br/>
{{admissiondate | date }} <br/><br/>
{{rollno | number }}
</div>
<script src = "https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js">
</script>
<!-- <script src = "https://code.angularjs.org/1.3.14/i18n/angular-locale_da-dk.js">
</script> -->
<script>
var mainApp = angular.module("mainApp", []);
mainApp.controller('StudentController', function(scope) {scope.fees = 100;
scope.admissiondate = new Date();scope.rollno = 123.45;
});
</script>
</body>
</html>
输出
在Web浏览器中打开文件testAngularJS.htm,查看结果。