AngularJS – isUndefined() 方法
pythonserver side programmingprogramming更新于 2025/12/14 9:48:17
AngularJS 中的 isUndefined() 方法主要检查引用是否已定义。如果函数内部传递的引用未定义或未定义,则此方法将返回 True,否则将返回 False。
语法
angular.isUndefined(value)
示例 − 检查引用是否为未定义
在 Angular 项目目录中创建文件"isUndefined.html.3"并复制粘贴以下代码片段。
<!DOCTYPE html>
<html>
<head>
<title>angular.isUndefined()</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">
Welcome to Tutorials Point
</h1>
<h2>AngularJS | angular.isUndefined()</h2>
<div ng-controller="example">
<b>Name: {{name}}</b>
<br><br>
{{isUndefined}}
<br><br>
<b>Name: {{name2}}</b>
<br><br>
{{isUndefined1}}
</div>
<!-- Script for passing the values and checking... -->
<script>
var app = angular.module("app", []);
app.controller('example',['$scope', function ($scope)
{
// Defining the keys & values
$scope.name = "SIMPLY LEARNING";
$scope.name2;
$scope.isUndefined = angular.isUndefined($scope.name) == true
? "$scope.name is Undefined."
: "$scope.name is Defined.";
$scope.isUndefined1 = angular.isUndefined($scope.name2)== true
? "$scope.name2 is Undefined."
: "$scope.name2 is Defined.";
}]);
</script>
</body>
</html>
输出
要运行上述代码,只需转到您的文件并将其作为普通 HTML 文件运行。您将在浏览器窗口中看到以下输出。

在代码中,$scope.name 已定义,而 $scope.name2 并非未定义。因此,我们得到了此输出。
相关文章
有用资源
python 参考教程 - 该教程包含有关 python 的更多信息:https://www.cainiaomax.com/python/

