AngularJs Check if a key exists in an object
home
Run
screen_rotation
fullscreen
cloud_download
<!DOCTYPE html> <html lang="en"> <head> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.min.js"></script> <script> var myApp = angular.module("myApp", []); myApp.controller("myController", function($scope) { $scope.obj1 = {"key1":99}; $scope.result = ''; $scope.textvalue = "key1"; $scope.checkKey = function() { var txtVal = $scope.textvalue; if(!(txtVal in $scope.obj1)){ $scope.result = "Key not Found."; }else{ $scope.result = "Key Exists in Object obj1."; } } }); </script> </head> <body> <div ng-app="myApp"> <div ng-controller="myController"> <input type="text" ng-model="textvalue" ><br> <button ng-click ="checkKey()" >Check Key Exists</button> <br> Result = {{result}}<br> </div> </div> </body> </html>
<!DOCTYPE html> <html lang="en"> <head> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.min.js"></script> <script> var myApp = angular.module("myApp", []); myApp.controller("myController", function($scope) { $scope.obj1 = {"key1":99}; $scope.result = ''; $scope.textvalue = "key1"; $scope.checkKey = function() { var txtVal = $scope.textvalue; if(!(txtVal in $scope.obj1)){ $scope.result = "Key not Found."; }else{ $scope.result = "Key Exists in Object obj1."; } } }); </script> </head> <body> <div ng-app="myApp"> <div ng-controller="myController"> <input type="text" ng-model="textvalue" ><br> <button ng-click ="checkKey()" >Check Key Exists</button> <br> Result = {{result}}<br> </div> </div> </body> </html>
Copyrights@tutorialsplane.com