AngularJS德语区域脚本未生效,货币过滤器不显示欧元符号求助
It looks like the core issue here is how you're loading the German locale script—your current path points to a local filesystem location that your web server can't access, so Angular never actually loads the locale data. Let's walk through the fixes step by step:
1. Fix the Locale Script Path
Your current script tag references /usr/local/lib/node_modules/angular-i18n/angular-locale_de-de.js, which is an absolute path on your Ubuntu server's filesystem. Web servers don't serve files from arbitrary system directories by default, so this file is likely returning a 404 error (check your browser's dev tools Network tab to confirm).
Solution Options:
- Copy the locale file to your project:
Copyangular-locale_de-de.jsfrom/usr/local/lib/node_modules/angular-i18n/to a public directory in your project (e.g.,js/i18n/), then update the script tag:<script src="js/i18n/angular-locale_de-de.js"></script> - Use a CDN:
For AngularJS 1.6.4, use a matching version of the locale script from a CDN:<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-i18n/1.6.4/angular-locale_de-de.js"></script>
2. Verify Script Loading Order
Ensure your scripts are loaded in this exact order:
- AngularJS core
- Locale script
- Your app/controller script
Your existing order is correct, but fixing the path will make the locale data available to Angular.
3. Corrected Working Code Example
Here's your code with the CDN locale script and proper structure:
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-i18n/1.6.4/angular-locale_de-de.js"></script> </head> <body> <div ng-app="myApp" ng-controller="costCtrl"> <h1>Price: {{ price | currency}}</h1> </div> <script> var app = angular.module('myApp', []); app.controller('costCtrl', function($scope) { $scope.price = 58; }); </script> <p>The currency filter formats a number to a currency format.</p> </body> </html>
4. Troubleshooting Angular Dynamic Locale (If You Still Want to Use It)
If you're set on using angular-dynamic-locale, make sure you've configured it correctly:
- Inject the module into your app:
var app = angular.module('myApp', ['tmh.dynamicLocale']); - Set the locale path and activate it in your controller:
app.config(function(tmhDynamicLocaleProvider) { tmhDynamicLocaleProvider.localeLocationPattern('/path/to/angular-i18n/angular-locale_{{locale}}.js'); }); app.controller('costCtrl', function($scope, tmhDynamicLocale) { tmhDynamicLocale.set('de-de'); $scope.price = 58; });
Again, ensure the localeLocationPattern points to a path your web server can serve.
Quick Fix: Explicit Currency Symbol
If you need an immediate workaround while fixing the locale setup, you can pass the euro symbol directly to the currency filter:
<h1>Price: {{ price | currency:'€' }}</h1>
Remember to check your browser's console for any 404 errors or Angular warnings—those will give you clues if the locale script still isn't loading properly.
内容的提问来源于stack exchange,提问作者Paul Rousseau

