Introduction about ng-messages in AngularJs

Introduction about ng-messages in AngularJs

The AngularJs ng-messages is a directive and its used for displaying the messages within the templates. The messages can be custom messages, error messages, or any kind of messages for the end user. The ngMessages is added in AngularJs 1.3 version.

You can download to from below URLs.


The example in detail about using ng-messages

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title> Introduction about ng-messages in AngularJs</title>
    <script src="//code.angularjs.org/1.4.0/angular.js"></script>
    <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.0/angular-messages.js"></script>
    <script>
        var app = angular.module('app', ['ngMessages']);
        app.controller('MainCtrl', ["$scope", function ($scope) {
            $scope.email = 'anil.singh@gmail.com';
        }]);
    </script>
</head>
<body ng-app="app" ng-controller="MainCtrl">
    <div>
        <h2> Introduction about ng-messages in AngularJs </h2>
    </div>
    <form name="form">
        <div ng-class="{'has-error': form.email.$touched && form.email.$invalid }">
            Email : <input type="email" name="email" ng-model="email" required>
            <div ng-messages="form.email.$error" ng-if="form.email.$touched">
                <div ng-messages-include="msg.html"></div>
            </div>
        </div>
        <div>
            <button type="submit">Submit</button>
        </div>
    </form>
        <div>
        <p>
            <p>form.email.$error = {{ form.email.$error | json }}</p>
        </p>
    </div>
</body>
</html>



ANIL SINGH

Anil Singh is an author, tech blogger, and software programmer. Book writing, tech blogging is something do extra and Anil love doing it. For more detail, kindly refer to this link..

My Tech Blog - https://www.code-sample.com/
My Books - Book 1 and Book 2

Introduction about ng-messages in AngularJs Introduction about ng-messages in AngularJs Reviewed by Anil Singh on 5:25 AM Rating: (5)
www.code-sample.com/. Powered by Blogger.
^