python ruby-programming-language Smalltalk Vue.js Knockoutjs TypeScript JavaScript, OOPs JavaScript Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 4 Angular 2 AngularJs 1.x NodeJs Perl Programming R Programming RequireJs Rust Programming Backbonejs closure programming language go-programming-language kotlin-programming-language
What is AngularJs isDefined() Function?

What is AngularJs isDefined() Function?

The angular isDefined() function is  use to check the value or references in defined or not in angular $scope.

If the value or reference is defined then return the true otherwise return false.

The live demo, click on link http://embed.plnkr.co/Cp2KA2/

Syntax :

                   angular.isDefined($val);      

The isDefined() function is case sensitive and takes a $val and returns true/false.

JavaScript Code :

       var app = angular.module('myApp', []);
        app.controller('myCtrl', ['$scope', function ($val) {
            $val.welcomeMsg = function () {
                if (angular.isDefined($val.message)) {
                    $val.lblmessage = 'Welcome you  ' + $val.message + '!';
                } else {
                    $val.lblmessage = 'Please enter your name';
                }
            }
        }]);

The example in detail as give below

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>AngularJSisDefined() Function</title>
    <script src="https://code.angularjs.org/1.4.9/angular.js"></script>
    <script>
        var app = angular.module('myApp', []);

        app.controller('myCtrl', ['$scope', function ($val) {

            $val.welcomeMsg = function () {
                if (angular.isDefined($val.message)) {
                    $val.lblmessage = 'Welcome you  ' + $val.message + '!';
                } else {
                    $val.lblmessage = 'Please enter your name';
                }
            }
        }]);
    </script>
</head>
<body ng-app="myApp" ng-controller="myCtrl">
    <div>
        <input type="text" ng-model="message" placeholder="Type a message" />
        <button ng-click="welcomeMsg()">Submit</button>
    </div>
    <h1>Result : {{lblmessage}}</h1>
</body>
</html>

Result : go for live demo http://embed.plnkr.co/Cp2KA2/





ANIL SINGH

Hi there! Welcome to my blog. My name is Anil Singh. I'm a author of this blog. For more detail about me, kindly refer to this link..
My Blogs - http://code-sample.com and http://code-sample.xyz
My Books - Interview Questions and Answers Books- Get Your Book in 15+ Digital Stores Worldwide..

You Might Also Like
www.code-sample.com/. Powered by Blogger.
ASK Questions