AngularJS API介绍和用法示例

2021年3月26日16:26:24 发表评论 776 次浏览

AngularJS API用于比较, 迭代和转换对象。基本AngularJS API包括

  • angular.isString()
  • angular.lowercase()
  • angular.uppercase()
  • angular.isNumber()

1. angular.isString()

用于检查对象是否为字符串, 如果对象为字符串则返回true, 否则返回false。

例子:

<!-- Write HTML code here -->
<!DOCTYPE html>
< html >
   < head >
< script src =
"https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js" >
</ script >
   </ head >
   < body >
  
     < div ng-app = "gfg" ng-controller = "gfgCntrl" >
     < p >{{ object }}</ p >
     < p >{{ apiRes }}</ p >
     </ div >
  
     < script >
       var app = angular.module('gfg', []);
       app.controller('gfgCntrl', function($scope) {
           $scope.object = "lsbin";
           $scope.apiRes = angular.isString($scope.object);
       });
     </ script >
  
   </ body >
</ html >

输出如下:

AngularJS API介绍和用法示例1

2. angular.lowercase()

它用于将字符串的所有字符转换为小写字符。

例子:

<!-- Write HTML code here -->
<!DOCTYPE html>
< html >
   < head >
< script src =
"https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js" >
</ script >
   </ head >
   < body >
  
     < div ng-app = "gfg" ng-controller = "gfgCntrl" >
     < p >{{ object }}</ p >
     < p >{{ apiRes }}</ p >
     </ div >
  
     < script >
       var app = angular.module('gfg', []);
       app.controller('gfgCntrl', function($scope) {
           $scope.object = "lsbin";
           $scope.apiRes = angular.lowercase($scope.object);
       });
     </ script >
  
   </ body >
</ html >

输出如下:

AngularJS API介绍和用法示例2

3. angular.uppercase()

它用于将字符串的所有字符转换为大写字符。

例子:

<!-- Write HTML code here -->
<!DOCTYPE html>
< html >
   < head >
< script src =
"https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js" >
</ script >
   </ head >
   < body >
  
     < div ng-app = "gfg" ng-controller = "gfgCntrl" >
     < p >{{ object }}</ p >
     < p >{{ apiRes }}</ p >
     </ div >
  
     < script >
       var app = angular.module('gfg', []);
       app.controller('gfgCntrl', function($scope) {
           $scope.object = "lsbin";
           $scope.apiRes = angular.uppercase($scope.object);
       });
     </ script >
  
   </ body >
</ html >

输出如下:

AngularJS API介绍和用法示例3

4. angular.isNumber()

用于检查对象是否为数字。如果object是一个数字, 则返回true, 否则返回false。

例子:

<!-- Write HTML code here -->
<!DOCTYPE html>
< html >
   < head >
< script src =
"https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js" >
</ script >
   </ head >
   < body >
  
     < div ng-app = "gfg" ng-controller = "gfgCntrl" >
     < p >{{ object }}</ p >
     < p >{{ apiRes }}</ p >
     </ div >
  
     < script >
       var app = angular.module('gfg', []);
       app.controller('gfgCntrl', function($scope) {
           $scope.object = "lsbin";
           $scope.apiRes = angular.isNumber($scope.object);
       });
     </ script >
  
   </ body >
</ html >

输出如下:

AngularJS API介绍和用法示例4

木子山

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: