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

Hey! I'm Anil Singh. I author this blog. I'm Active Blogger, Programmer. I love learning new technologies, programming, blogging and participating the forum discussions more...
My Blogs - http://www.code-sample.com and http://www.code-sample.xyz
My Books - Google Amazon and Flipkart Book Store!

You Might Also Like
Post a Comment
www.code-sample.com/. Powered by Blogger.
ASK Questions
SQL Server NodeJs TypeScript JavaScript Angular SQL Server My Book