如何將字串轉換為大寫?
有時,我們可能需要用大寫字母表示姓名或字串。 要將 AngularJS 中的字串轉換為大寫,我們可以使用大寫過濾器將字串的大小寫更改為大寫。
語法
- 在 HTML 模板繫結中
{{uppercase_expression | uppercase}}
- 在 JavaScript 中
$filter('uppercase')()
示例 − 轉換為大寫
在 Angular 專案目錄中建立一個檔案"uppercase.html",並複製貼上以下程式碼片段。
<!DOCTYPE html> <html> <head> <title>uppercase Filter</title> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script> </head> <body ng-app="app" style="text-align:Center"> <h1 style="color:green"> Welcome to Tutorials Point </h1> <h2 style="color: grey;"> AngularJS | UpperCase Filter </h2> <div ng-controller="example"> <p> <h2> Original: {{message}} </h2> <h2> Modified: {{message | uppercase}} </h2> <p> </div> <script> angular.module('app', []) .controller('example',['$scope', function($scope) { $scope.message = 'simply learning'; }]); </script> </body> </html>
輸出
若要執行以上程式碼,只需轉到你的檔案並像普通 HTML 檔案一樣執行它。 你將在瀏覽器視窗中看到以下輸出。
廣告