AngularJs is a framework based on Javascript developed by Google to create web applications. AngularJs is an open-source framework that developers primarily use to build dynamic websites or web applications. The main reasons it is famous as a framework are its built-in services or modules and code reusability in the application.
In this blog, we will learn how to create a dynamic AngularJS application using the AngularJS framework. Still, before developing our AngularJS application, we need to understand the dynamic web application.
Dynamic Web Application
In simple terms, a dynamic web application is an application that works in real time. For example, if a user is interacting with the application, then it should display changes according to the user's request.
The content in the dynamic web application must be updated regularly. E-commerce websites are excellent examples of dynamic web applications. The dynamic web application can be complex to develop or manage due to multiple requests handling events.
Developing a dynamic web application is a great way to learn web technology. This blog will teach us how to create a TODO list application using AngularJS. TODO is a beginner-friendly project that teaches you how to use various built-in modules.
Create TODO Application
In this section, we will implement our AngularJS application with the help of the AngularJS framework.
First, we will create an angular project and open it in the VSCode, or you can use any editor.
Then, in the project folder, create their files index.html, todoscript.js, and todoapp.css to create our AngularJS application.
Index.html
Create the basic Html structure in the file and include the scripts in the <head> tag.
Our next step will be to print the TODO List Application on the screen. To check whether our application is running or not. Add <h1>TODO List Application</h1> in body.
Now include the ng-app and ng-controller directives in the HTML file. These directives are used for data binding.
In the above code, we are we have created a div where we will display our todos in the <li> tag. We will use the ng-repeat directive to iterate over the todo array which we will create in todoscript.js. In the array, we have two objects. One is a task, and the other is a stat. The stat object is to check the status of the todo, and by default, it will be false.
We have created an input tag with ng-model directive with value todovalue to store user input in the todo array. On clicking the “add todo” button, it will redirect to the addtodo() function.
Let's create an addtodo function in the todoscript.js file.
If the user input is empty, it will not show any result; else, it will display the user input on the screen when we click on add todo button.
Our next task will be to remove the checked elements from the list. First will add a “clear list” button. This button will redirect to the cleartodo() function in the script file.
If the status of the todo is true, then we will remove it from the array and update our todo array and display it on the screen.
Now how we will change the status? This will be done with checkbox input.
<input type="checkbox" ng-model="todo.stat">
We have bound the stat object of the todo array with checkbox input using the ng-model directive, and if the checkbox is true, then the status of the todo array element will be changed.
One last task will be to display the total current tasks in todo on the screen. We need to create a totaltodo() function and add it to the Html application,
On clicking on “Add todo” button, we get the updated list:
Checking and Clearing the Todo
After checking in the todo, you need to click the clear list button to remove it.
Updated list after clearing some todo tasks:
We can also see that the current todo task count is shown above the tasks, which keeps incrementing on adding tasks and decreases on removing tasks.
Frequently Asked Questions
What is a dynamic web application?
The dynamic web application is an application that works in real time. The content in the dynamic web application must be updated regularly.
What are examples of dynamic web applications?
E-commerce websites, blog applications, etc, are two examples of dynamic web applications.
Is Angular open source?
Yes, Angular is an open-source web framework developed by Google.
What are directives in AngularJS?
Directives are labels that we can use to extend our basic HTML structure and add some functionality to it, for example, data binding.
How do I run an Angular JS app locally?
An angular application can be compiled and run locally using the command ng-serve. This opens the localhost on your system.
Conclusion
In this blog, we have discussed a basic angular application. We have learned about the dynamic web application, and we have implemented a to-do list application as an example of a real-time application.
To learn more about AngularJS, you can check out the following articles.