If you want to find out whether HTML element exists in the page or not, then you have to use angular.element property. For in-existed elements, the result of  angular.element will be []. For in-existed functions and variables, we can use null verification.
<button ng-click="isElementExists('divID')">
  Is divID exists ?
<button ng-click="isElementExists('divID123')">
  Is divID123 exists ?
<button ng-click="isSampleFunctionExists()">
  Is sampleFunction exists ?
<button ng-click="isFunction123Exists()()">
  Is function123 exists ?
<div id="divID">
  This is divID element
function myCtrl($scope) {
    $scope.isElementExists = function(id) {
     var myEl = angular.element( document.querySelector('#'+ id ) );
     if(myEl == '[]') {
     } else {

    $scope.isSampleFunctionExists= function() {
      alert($scope.sampleFunction != null);

    $scope.isFunction123Exists= function() {
      alert($scope.function123 != null);

    $scope.sampleFunction = function(id) {

1 comment:

  1. Your blogs are authentic. I love them .Are you also searching for essay help? we are the best solution for you. We are best known for delivering quality essay help.



Popular Posts