Sunday, September 20, 2015

Angular ng-hide

ng-hide : Shows or hides the given HTML element based on the expression provided to the ngHide attribute.This helps when creating Angular apps since our single page applications will most likely have many moving parts that come and go as the state of our application changes

The great part about these directives is that we don’t have to do any of the showing or hiding ourselves with CSS or JavaScript.

ex as shown below: If firstname model has values last name is shown.

Edit in plunkr

<!DOCTYPE html>
<html ng-app="myApp">
    <script src=""></script>
    <link rel="stylesheet" href="">
 <meta charset="utf-8" />
<body >
    <div class="container">
        <div ng-controller="userctrl">
            <p ng-hide="firstName">
                First Name: <input type="text" ng-model="firstName"><br>
                Full Name: {{firstName }}
            <p ng-hide="!firstName">
                Last Name : <input type="text" ng-model="firstName"><br>
                Last Name: {{lastName }}

    var app = angular.module('myApp', []);
    app.controller('userctrl', function ($scope) {
        $scope.firstName = "";
        $scope.lastName = "Kudupu";


Note:Last name is hidden till first name is entered 

No comments:

Post a Comment