AngularJS angular.isArray()函数

2021年3月11日17:07:19 发表评论 785 次浏览

angular.isArray()函数

AngularJS中用于返回

true

如果引用是数组, 并且

false

如果不是数组。

语法如下:

angular.isArray(value)

返回值:如果该值是一个数组, 则返回TRUE, 否则将返回FALSE。

范例1:

< html >
     < head >
         < title >angular.isArray()</ 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" >lsbin</ h1 >
  
         < h2 >angular.isArray()</ h2 >
  
         < div ng-controller = "geek" >
             < b >Sorting Algos:</ b >
             < div ng-repeat = "i in sort" >{{i.name}}</ div >
             < br >< br >
             isArray: {{isArray}}
         </ div >
  
         < script >
         var app = angular.module("app", []);
         app.controller('geek', ['$scope', function ($scope) {
             $scope.sort = [];
             var values = [
             { name: 'Merge sort' }, { name: 'Quick sort' }, { name: 'Bubble sort' }
             ];
             if (angular.isArray(values)) {
                 $scope.isArray = true;
                 angular.forEach(values, function (value, key) {
                     $scope.sort.push(value)
                 })
             }
         }]);
         </ script >
     </ body >
</ html >

输出如下:

isarray

范例2:

<!DOCTYPE html>
< html >
     < head >
         < title >angular.isArray()</ 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" >lsbin</ h1 >
         < h2 >angular.isArray()</ h2 >
         < div ng-controller = "geek" >
         < b >Input: </ b >{{name}}
         < br >< br >
             < b >isArray:</ b > {{isArray}}
         </ div >
         < script >
             var app = angular.module("app", []);
             app.controller('geek', ['$scope', function ($scope) {
                 var values = 'lsbin';
                 $scope.name = values;
                 $scope.isArray = angular.isArray(values)
             }]);
         </ script >
     </ body >
</ html >

输出如下:

isarray

木子山

发表评论

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