Skip to main content

Control state and validity with ngModel in angular2

        A ng-model is a form input property to two-way bind in a form control model. We are declared n number of ng-models, This model requires a validation for directive and component side also. Most of the user experience is apply with in directive because of didn't ready to waste the time to submit a form and validate in server side.

       In line validation, the very important role is played in angular and bootstrap framework. This form validation is declared a mandatory property in mg-model means bootstrap is binding in a directive for a hash class in angular.

Form Validation states:

State Class if true Class if false
The control has been visited. ng-touched ng-untouched
The control's value has changed. ng-dirty ng-pristine
The control's value is valid. ng-valid ng-invalid


Example:

<input type="text" #myNameRef="ngModel" required minlength="5" class="form-control" name="name" ngModel>
        <!-- avaialble input validation class names -->
        <{{myNameRef.className}}

Here is show the state of the validation is available in bootstrap validation classes shown.

Other Example:

<div *ngIf=" myNameRef.errors && (myNameRef.dirty || myNameRef.touched)">
            <div [hidden]=" !myNameRef.errors.required ">
                Please enter the name
            </div>
            <div [hidden]=" !myNameRef.errors.minlength ">
                Please enter minum 5 character
            </div>
        </div>

Comments

Popular posts from this blog

How has lockdown impacted Indian farmers?

How has lockdown impacted Indian farmers?             Generally compare to other sectors it's not major impacted by our Indian farmers but we acceptable minor impacts. Here we separate major two farming cultures one is mono farming culture another one poly farming culture. Mono farming :             The major impacts from our Indian farmer for monoculture. Here I have briefly explained what are the things we had faced our local farmers. Here I explain two different crops type: Daily crops : * We harvest more than 100-kilo grams daily crops like brinjal but we unable to sell those in local markets. * We are unable to reach urban markets. * We don't have enough transport facilities. * We unable buy require fertilizer and other complements * In the early stage we are facing manpower shortage but later it's not an issue. * We unable to do value-added products. * Waste is very high for somedays Se...

How to use ng-href directive in AngularJS

ng-Href Directive                  ng-Href directive is hyper link markup to a text in angularJs. This hyperlink will change able to implement dynamic url {{hash}} value. Hash value to assign in a controller to happened user click event fire to assign dynamic url. This Value is undefined means it will return to 404 page. ng-Href directive Example  HTML:      <div ng-app="anchor">     <div ng-controller="anchorController">         <a ng-href="http://www.google.com" ng-click="show($event)">Anchor Tag</a>     </div>   </div> Javascript :  var anch = angular.module('anchor', []); anch.controller('anchorController',['$scope', '$window', function($scope, $window){     $scope.show = function(obj) {       $window.open(obj.target.href);     } }]); Result :  Dem...

Google's Neverending Big Adventure

Google's Neverending Big Adventure   Why would Google want to send its Street View cameras into a vast crack in the Earth where there's nary a street to be found? It can't be as simple as "because it can." There must be some financial motive. Perhaps -- but monetization "is not how Google typically thinks about it," said tech analyst Greg Sterling. "This is part of the logic of Google's mission to map the real world in a complete way." In its ongoing effort to create the perfect map of the world at ground level, Google took a trek into the Grand Canyon this week. Although this is part of its Google Maps Street View project, there are of course no streets in the national park. Google Street View Product Manager Ryan Falor Google Street View Product Manager Ryan Falor controls the Trekker with his Android device. Earlier this month, Google announced that it had doubled the number of special collections in its Street View catalo...