AngularJS angular.isDefined()函数详解及示例
AngularJS angular.isDefined()函数,AngularJS 中的angular.isDefined() 函数用于确定 isDefined 函数内部的值是否定义。如果传递的值已定义,则返回 true,否则返回 false。
语法:
angular.isDefined( value )
返回值:如果定义了传递的值,则返回true,否则返回false。
示例:使用 angular.isDefined() 函数来确定 isDefined 函数内部的值是否已定义。
<!DOCTYPE html>
<html>
<head>
<title>angular.isDefined()</title>
<script src=
"//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.isDefined()</h2>
<div ng-controller="geek">
<b>Date:</b> {{date}}<br><br>
{{isDefined}}
</div>
<!-- Script to uses angular.isDefined() function -->
<script>
var app = angular.module("app", []);
app.controller('geek', ['$scope', function ($scope) {
$scope.date;
$scope.isDefined = angular.isDefined($scope.date)
== true ? "$scope.date is defined."
: "$scope.date is undefined.";
}]);
</script>
</body>
</html>
输出:
未定义date:
如果 Date 已定义且其值为“2019-04-07T23:46:20.586”:
常见问题FAQ
- 程序仅供学习研究,请勿用于非法用途,不得违反国家法律,否则后果自负,一切法律责任与本站无关。
- 请仔细阅读以上条款再购买,拍下即代表同意条款并遵守约定,谢谢大家支持理解!