Wednesday, 16 November 2016

Ng-Repeat Example in Angularjs

In the below of code we have used ng-repeat angualr directive which will be repeat every time in the array which has been created and with the help of $scope object we will make communication between the html elementes and Controller.


<!DOCTYPE html>
<head>
    <title>Welcome For Learn Ng-Repeat Directive/title>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js"></script>
</head>
<body ng-app="app">
    <div ng-controller="StudentListCtrl">
        <ul>
            <li ng-repeat="student in students">{{student.name}}</li>
        </ul>
    </div>
<script>
    var app = angular.module("app", []);
    app.controller('StudentListCtrl', ['$scope', function ($scope) {
        $scope.students = [{ name: 'Sunil' }, { name: 'Kamal' }, { name: 'Rajesh' },
{ name: ' Arpan' }, { name: 'Amit' }];
    }]);
</script>
</body>
</html>
-------------------
OUTPUT: -

  • Sunil
  • Kamal
  • Rajesh
  • Arpan
  • Amit

Friday, 11 November 2016

Textbox Accept only Numbers in AngularJS

Below the code which is help full for you guys...if you want to enter only numbers in Textbox excepting alphabets and special character.

Include below the line Html File:

Number : <input type="text" name="quantity" id="quantity" />&nbsp;<span id="errmsg"></span>

Included the below the code in JS:
--------
$(document).ready(function () {
  //called when key is pressed in textbox
  $("#quantity").keypress(function (e) {
     //if the letter is not digit then display error and don't type anything
     if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) {
        //display error message
        $("#errmsg").html("Digits Only").show().fadeOut("slow");
               return false;
    }
   });
});
-------------------
Include the below CSS in Css File:

#errmsg
{
color: red;
}

OutPut: