AngularJS has directives for binding application data to the attributes of HTML DOM elements.
The ng-disabled directive binds AngularJS application data to the disabled attribute of HTML elements.
The ng-disabled
directive binds the application data mySwitch
to the HTML button's disabled
attribute.
The ng-model
directive binds the value of the HTML checkbox element to the value of mySwitch
.
If the value of mySwitch
evaluates to true
, the button will be disabled.
If the value of mySwitch
evaluates to true
, the button will be disabled:
If the value of mySwitch
evaluates to false
, the button will not be disabled:
The ng-show directive shows or hides an HTML element.
You can use any expression that evaluates to true or false:
This example demonstrates two-way data binding using AngularJS. As the user types their name, it is instantly displayed on the screen. The Submit button remains disabled until a name is entered, showing how AngularJS dynamically controls UI behavior based on input.
AngularJS strings are like JavaScript strings:
This code creates a responsive Student Registration form using AngularJS for AIT Academy. It includes input fields for name, contact number, email, and course selection. Each field is progressively enabled based on the previous field's valid input to guide the user. The form uses the ng-disabled, ng-model, and ng-submit directives to manage form behavior and validation. Once all fields are properly filled and the terms are agreed to, the submit button becomes active, and clicking it shows an alert message: “We appreciate your interest and will respond as soon as possible.”