AngularJS Events
AngularJS Events
AngularJS has its own HTML event directives.
ng-click directive
ng-clickThe directive defines the AngularJS click event.
AngularJS instance
<
div
ng-app=
""
ng-controller=
"myCtrl"
<
button
ng-click=
"count = count + 1"
Click me!
<
/button
<
p
{{ count }}
<
/p
<
/div
Try it »
Hide HTML element
ng-hideDirective used to set whether an application part is visible.
ng-hide="true"Set the HTML element to be invisible.
ng-hide="false"Set the HTML element to be visible.
AngularJS instance
<
div
ng-app=
"myApp"
ng-controller=
"personCtrl"
<
button
ng-click=
"toggle()"
Hide/Show
<
/button
<
p
ng-hide=
"myVar"
Name:
<
input
type=
"text"
ng-model=
"firstName"
<
br
Name:
<
input
type=
"text"
ng-model=
"lastName"
<
br
<
br
Full Name:
{{firstName + " " + lastName}}
<
/p
<
/div
<
script
var app = angular.module('myApp', []);
app.controller('personCtrl', function($scope) {
$scope.firstName = "John",
$scope.lastName = "Doe"
$scope.myVar = false;
$scope.toggle = function() {
$scope.myVar = !$scope.myVar;
};
});
<
/script
Try it »
Application parsing:
Part onepersonControllerSimilar to the controller chapter.
The application has a default property:$scope.myVar = false;
ng-hideDirective settings
Whether the element and two input fields are visible, based onthe value of myVar (true or false) to set visibility.The value (true or false) to set visibility.
toggle()Function to togglemyVarThe value of the variable (true and false).
ng-hide="true"Makes the elementinvisible.
Display HTML elements
ng-showDirectives can be used to set whether a part of the application isvisible..
ng-show="false"can set an HTML elementto be invisible.
ng-show="true"It can be set to make an HTML element visible.
The following examples use the ng-show directive:
AngularJS instance
<
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
Last 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
Try it »