Events of AngularJS Learning

Source: Internet
Author: User

1.ng-click directive: Defines the Angularjs click event

<div ng-app= "" ng-controller= "Myctrl" >

<button ng-click= "Count=count+1" > Point me! </button>

<p>{{count}}</p>

</div>

2. Hide HTML elements:

The **ng-hide directive is used to set whether the app part is visible

**ng-hide= "true" to set HTML element not visible

**ng-hide= "false" to set HTML elements to be visible

<div ng-app= "myApp" ng-controller= "Personctrl" >

<button ng-click= "Toggle ()" > Hide/Show </buttton>

<p ng-hide= "MyVar" >//ng-hide instruction Settings <p> elements and two input fields are visible, depending on the value of MyVar (True or false) to set whether it is visible

Name: <input type= "text" ng-model= "FirstName" ><br>

Name: <input type= "text" ng-model= "LastName" ><br>

<br>

Full name:{{firstname+ "" +lastname}}

</p>

<script>

var app=angular.module (' myApp ', []);

App.controller (' Personctrl ', function ($scope) {

$scope. Firstname= "John",

$scope. Lastname= "Doe",

$scope. Myvar=false;

$scope. Toggle=function () {//toggle () function toggles the value of the MyVar variable (TRUE or FALSE)

$scope. myvar=! $scope. MyVar ();

}

});

</script>

</div>

3. Display HTML elements: The ng-show directive is used to set whether a part of the app is visible;

**ng-show= "false" to set HTML element not visible

**ng-show= "True" to set HTML elements to be visible

<div ng-app= "myApp" ng-controller= "Personctrl" >

<button ng-click= "Toggle ()" > Hide/Show </button>

<p ng-show= "MyVar" >

Name: <input type= "text" ng-model= "FirstName" ><br>

Name: <input type= "text" ng-model= "LastName" ><br>

<br>

Name: {{firstname+ "" +lastname}}

</p>

</div>

<script>

var app=angular.module (' myApp ', []);

App.controller (' Personctrl ', function ($scope) {

$scope. Firstname= "John",

$scope. Lastname= "Doe"

$scope. Myvar=true;

$scope. Toggle=function () {

$scope. myvar=! $scope. MyVar;

}

});

</script>

Events of AngularJS Learning

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.