Execute
<!DOCTYPE html> <html> <head> <title>Wikitechy AngularJS Tutorial</title> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script> </head> <body> <form ng-app="myApp" name="Form" ng-controller="TextCtrl"> <h3>input[text] directive example in AngularJS</h3> Single word: <input type="text" name="input" ng-model="text" ng-pattern="/^[a-zA-Z]+$/" ng-trim="false" required > <span ng-show="Form.input.$error.required"><br/><br/> Required!</span> <span ng-show="Form.input.$error.pattern"><br/><br/> Single Word only!</span> <p>text = {{ text }}</p> <p>Form.input.$valid = {{ Form.input.$valid }}</p> <p>Form.input.$error = {{ Form.input.$error }}</p> <p>Form.$valid = {{ Form.$valid }}</p> <p>Form.$error.required = {{ !!Form.$error.required }}</p> </form> <script> var app = angular.module('myApp', []); app.controller('TextCtrl', function($scope) { }); </script> </body> </html>
www.wikitechy.com © Copyright 2016. All Rights Reserved.