Hi Deep,

This might will help you ...



*<html ng-app="myNoteApp">*
*  <head>*
*     <title>My Notepad with Char limit</title>*
*    <script 
src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js";></script>*

*    <script>*
*      var app = angular.module("myNoteApp", []);*
*      app.controller ("notectrl",function ($scope)*
*      {*
*        //Basic variables declaration*
*        $scope.Text ="";*
*        $scope.limit = 10;*
        
*        //Function 1 *
*        $scope.charactersLeft = function (){*
          
*        ////Testing Char limits in charactersLeft Function 1 *
*        if ($scope.Text.length > $scope.limit)*
*        {*
*           window.alert("Warning !")*
*        }*
        
*        else *
*        if ($scope.Text.length == $scope.limit){*
*          $scope.Notallow = function (){*
*            ////Testing with new NotAllow function in elseif in 
charactersLeft Function 1 *
*          window.alert("Your text limit has reached");*
*          }//NotAllow function :end *
*        }*
        
*        else{*
*        return $scope.limit - $scope.Text.length;*
*        };//Default else :end *
*        };//Function 1 :end *
        
*        //Function 2 *
*        $scope.clearAllbtn = function (){*
*        return $scope.Text ="";*
*        };//Function 2 :end *
        
*      });*
*    </script>*
*  </head>*
*  <body>*
*    <div ng-controller="notectrl">*
*      <p>*
*      <textarea ng-model="Text"  ng-keydown="Notallow()">*
*      </textarea>*
*      <br><br>*
*      <p>Characters remaining: *
*      <span ng-bind="charactersLeft()"></span>*
*      </p>*
*      </p>*
*      <input type="button" ng-click="clearAllbtn()" value="Clear"/>*
*    </div>*
*  </body>*
*</html>*



On Monday, December 28, 2015 at 10:56:11 AM UTC+5:30, Deep Singhal wrote:
>
> I am new to Angular and in learning phase. I am not sure if this is the 
> appropriate forum to ask questions, but here it goes. I am having a comment 
> box and am trying to display the count of char that I typed in it. The 
> following code does not give me the count but the one commented does so
> ==================JS=============
> var myApp=angular.module("myApp",[]);
> myApp.controller("myController",["$scope",function($scope){
>     $scope.commentText="";
>    /* $scope.lenghtComment=function(){
>         return $scope.commentText.length;
>     };*/
>     $scope.lengthComment=$scope.commentText.length;
>
> }]);
> =========================================
> <!doctype html>
> <html>
>     <head lang="en">
>         <meta charset="utf-8"/>        
>         <title>Practice</title>
>     </head>
>     <body ng-app="myApp">
>         <div ng-controller="myController">
>             Enter your text <br>
>             <textarea rows="5" id="comments" 
> ng-model="commentText"></textarea>
>             <br>
>             Type Char:{{ lenghtComment }}   <!--   Type Char:{{ 
> lenghtComment() }}    -->  
>         </div>        
>         <script src="
> https://code.angularjs.org/1.5.0-beta.2/angular.min.js"; 
> type="text/javascript"></script>
>         <script src="prac.js" type="text/javascript"></script>
>     </body>
>     
> </html>
>

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to