AngularJS – isString() method

AngularJSWeb DevelopmentFront End Technology

The isString() method in AngularJS basically checks if a reference is a string value or not. This method will return True if the reference passed inside the function is a string, else it will return False.



Example − Check if the reference is a String or not

Create a file "isString.html" in your Angular project directory and copy-paste the following code snippet.

<!DOCTYPE html>

      <script src= "">

   <body ng-app="app" style="text-align:center">
      <h1 style="color:green">
         Welcome to Tutorials Point
      <h2>AngularJS | angular.isString()</h2>

      <div ng-controller="example">
         <b>Name: {{name}}</b>
         <b>Name: {{name2}}</b>
         <b>Name: {{name3}}</b>

      <!-- Script for passing the values and checking... -->
         var app = angular.module("app", []);
         app.controller('example',['$scope', function ($scope)
            // Defining the keys & values
            $ = "SIMPLY LEARNING";
            $scope.name2 = "";
            $scope.name3 = {"name": "tutorialsPoint"};

            $scope.isString = angular.isString($ == true
                ? "$ is a String."
                : "$ is not a String.";

            $scope.isString1 = angular.isString($scope.name2) == true
               ? "$scope.name2 is a String."
               : "$scope.name2 is not a String.";

            $scope.isString2 = angular.isString ($scope.name3) == true
               ? "$scope.name2 is a String."
               : "$scope.name2 is not a String.";


To run the above code, just go to your file and run it as a normal HTML file. You will see the following output on the browser window.

Observe that name and name2 are strings, whereas name3 is a key-value pair in the given code, which is why we got the output "$scope.name2 is not a String."

Published on 08-Oct-2021 10:55:57