There are numerous front end javascript frameworks, angularjs, react, backbone, and todomvc etc. Here, I choose to use Angular.js and test some interesting features. The functionalities of Angular js include filtering repeaters, two-way data binding, dependancy injection, template, routing, and service.
Directies are markers on a DOM element, such as an attribute, or element name, that attaches behaviors to the DOM element. Several build-in directives in Angular js are ngBind, ngDisable, ngClick, ngShow, and ngModel.
Demonstration
ng-bind
ngBind may bind the content of a HTML element with value of a given expression and update the value as the value of the expression changes. Here, I bind the name and nickname in the following sentence with the input text field.
Name:
Nickname:
My name is and my nickname is
ng-disable
ngDisabled sets the disabled attribute on the element as the expression inside ngDisabled is true. Here, I bind the expression Switch on the toggle checkbox. The button would be disabled as the checkbox is checked.
Toggle
ng-click
ngClick would evaluate the expression upon tap. This directive would be deprecated beginning with Angular 1.5. Click on the button and there's a scope variable incrementation.
form validation
Inputs of type email must have a value in the form of username@domainname. If the email is blank, a message of required email would be shown. If the format of the email isn't username@domainname, a message of invalid email would be shown.
Angular js setup
To start using Angular js, choose a version on the content deliver network of google or download to your local machine. In the script tag, put the corresponding url or path in the src attribute.
In the following script, declare a application variable from angular module and name the the application as myApp. The empty brackets indicate that there's no extra module to load. The controller is then declared with a name of validateCtrl and a constructor function. a new child scope will be created and made avaliable as an injectable parameter to the constructor function as $scope. Here, I set ip the initial state of a $scope object and attach a property called email.
Controller code
Surround the block that would use the Angular js with the div declaring ngApp then the Angular js would compile the expressions and directives.
ngBind
Bind the input text field with name and nickname using ngModel.
bgDisabled
Bind the checkbox with Switch using ngModel. And assign Switch as the expression in ngDisabled.
ngClick
The increment expression on the count variable would be executed once every time the button has been tabbed.
form validation
The novalidate attribute indicates that the form is not to be validated on submit. Instead, use the validation function of Angular and disable the submit button as the email field is empty or error invalidate in format.
Conclusion
Here, I only demonstrate a little part of Angular js. To fully explorer the power of Angular js, please visit the official website. As it's now transferring from Angular 1 to Angular 2, there might be many changes and other front-end may be good choices,too.