Showing posts with label angularJS. Show all posts
Showing posts with label angularJS. Show all posts

How to restrict textbox values in angularJS

In this article i show you how to get textbox value in angulaJS. First we need to add angularJS reference
in html page
Step1:- add angularJS reference in html page
    <script src="Scripts/angular.js"></script>
    <script src="Scripts/Script1.js"></script>
Script1.js is the javascript file for declaring module and controller

/// <reference path="angular.min.js" />
var app = angular.module("myapp",[])
    .controller("mycontroller", function ($scope)
    {
})
add reference to the javascriptfile
step2:-Add html page.In angularJS we have two directives ng-mimilenth ang ng-maxlenth for restricting textbox values.We are using expressions for getting textbox value.Expressions are declared by using bracess
    <div ng-app="myapp">
        <div ng-controller="mycontroller">
            <input type="text" ng-model="name" ng-maxlength="12" ng-minlength="5"  />
            <br />
            <br />
            {{name}}
        </div>
    </div>

Directives In angularJS

Below are the some important directives
  • ng-app :- Defines the root element of the application
  • ng-bind :-Bind the content of the html element to the application data
  • ng-blur   :-Specifies the behavior on blur event
  • ng-change :-Specifies an expression to evaluate when content is being changed by the user
  • ng-checked:-Specifies the element is checked or not
  • ng-class :-Specifies the CSS class on html element
  • ng-class-event :-Same as ng-class but effect only even rows
  • ng-class-odd :-Same as ng-class but effect only odd rows
  • ng-click :-It work as click event
  • ng-hide :- Hide or Shows html elements
  • ng-if  :-Removes the html elements if condition is false
  • ng-include :-Include the html to the application