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 = '[email protected]';
        }]);
    </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 Blogs - https://code-sample.com and https://code-sample.xyz
My Book1 - BEST SELLING ANGULAR BOOK (INCLUDING ALL VERSIONS 2, 4, 5, 6, 7)
My Book2 - ANGULAR 2 INTERVIEW QUESTIONS BOOK - Both Books are Available on WorldWide.

www.code-sample.com/. Powered by Blogger.