AngularJS angular.isObject()函数

AngularJS angular.isObject()函数

AngularJS中的angular.isobject()函数是用来确定_isobject函数中的参数是否是一个对象。如果引用是一个对象,它返回真,否则返回假。

语法:

angular.isobject(value);

参数:

  • value:这个参数值验证输入的值是否是一个对象。

返回值:如果传递的值是一个对象,它将返回真,否则返回假。

实例1:本实例描述了AngularJS中的angular.isObject()函数

<!DOCTYPE html>
<html>
  
<head>
    <script src=
"//ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.min.js">
    </script>
    <title>angular.isObject()</title>
</head>
  
<body ng-app="app" style="text-align:center">
    <h1 style="color:green">GeeksforGeeks</h1>
    <h2>angular.isObject()</h2>
    <div ng-controller="geek"> 
       <b>Input1: </b> 
       <span>
            <code>
                obj1 = {"Name": "Binary search"}
            </code>
        </span>
        <br>
        <b>isObject: </b>{{isObject1}}
        <br /><br><br> 
        <b>Input2: </b> 
        <code>
            "geeksforgeeks"
        </code>
        <br> 
        <b>isObject:</b> {{isObject2}} 
    </div>
    <script>
        var app = angular.module("app", []);
        app.controller('geek', ['scope', function(scope) {
            var obj1 = {
                "Name": "Binary search"
            };
            var obj2 = "geeksforgeeks";
            scope.isObject1 = angular.isObject(obj1);
            scope.isObject2 = angular.isObject(obj2);
        }]);
    </script>
</body>
</html>

输出:

AngularJS angular.isObject()函数

示例2:本示例描述了AngularJS中的angular.isObject()函数,其中两个输入值都得到了验证。

<!DOCTYPE html>
<html>
  
<head>
    <title>angular.isObject()</title>
    <script src=
"https://ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.min.js">
    </script>
</head>
  
<body ng-app="app" style="text-align: center">
    <h1 style="color: green">GeeksforGeeks</h1>
    <h2>angular.isObject()</h2>
    <div ng-controller="geek">
        <b>Input 1: </b>
        <span>
            <code> obj1 ={{val1}} </code>
        </span>
        <br /><br />
        <b> isObject: </b>{{isObject2}} 
        <br /><br />
        <b>Input 2:</b>
        <span>
            <code> obj2 = null; </code>
        </span>
        <br /><br />
        <b>isObject: </b> {{isObject1}}
    </div>
  
    <script>
        var app = angular.module('app', []);
        app.controller('geek', [
            'scope',
            function (scope) {
                var val2 = null;
                scope.val1 = [
                    { Name: 'Merge Sort' },
                    { Name: 'Quick Sort' },
                    { Name: 'Selection Sort' },
                ];
  
                scope.isObject1 =
                    angular.isObject(scope.val2) == true ? 'true.' : 'false';
  
                scope.isObject2 =
                    angular.isObject($scope.val1) == true ? 'true' : 'false';
            },
        ]);
    </script>
</body>
</html>

输出:

AngularJS angular.isObject()函数

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程