AngularJS angular.isDefined() Function (original) (raw)

Last Updated : 06 Sep, 2022

The angular.isDefined() function in AngularJS is used to determine the value inside isDefined function is defined or not. It returns true if the reference is defined otherwise returns false.

Syntax:

angular.isDefined( value );

Parameter value:

Return Value: It returns true if the passed value is defined otherwise returns false.

Example: This example uses angular.isDefined() function to determine the value inside isDefined function is defined or not.

HTML `

angular.isDefined()

GeeksforGeeks

angular.isDefined()

Date: {{date}}

{{isDefined}}
<!-- 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>

`

Output:

isDefined

isDate

Example 2: This example describes the usage of angular.isDefined() Function in AngularJS by specifying the current time.

HTML `

angular.isDefined()

GeeksforGeeks

angular.isDefined()

Time: {{ today| date : 'mediumTime'}}

{{isDefined}}
<!-- Script to uses angular.isDefined() function -->
<script>
    var app = angular.module('app', []);
    app.controller('geek', ['$scope',
        function($scope) {
            $scope.today = new Date();
            $scope.isDefined = 
            angular.isDefined($scope.today) == true ?
            '$scope.date is defined.' : '$scope.date is undefined.';
        },
    ]);
</script>

`

Output: