A list of 60 AngularJS exercises, categorized into different topics to cover basics, data binding, directives, routing, services, and advanced features.
Basic AngularJS Exercises
- Set up a basic AngularJS application and display “Hello, AngularJS!”.
- Use ng-appto initialize an AngularJS app in an HTML document.
- Bind a variable using ng-bindand display its value on the page.
- Create an input field with two-way binding using ng-model.
- Display a calculated result (e.g., { { 2 + 2 } }) using interpolation.
- Create a button that changes a value in the controller using ng-click.
- Create a list and use ng-repeatto loop through and display items.
- Display a message only when a condition is true using ng-if.
- Show or hide an element using ng-showandng-hide.
- Create a dropdown and display the selected value dynamically.
Controllers and Scope
- Define a controller and bind a variable to the $scope.
- Use multiple controllers on the same page and pass data between them.
- Create a function in a controller and invoke it from a button click.
- Create a calculator app with addition, subtraction, multiplication, and division.
- Pass data from a parent controller to a child controller using $scope.
- Use $watchto track changes in a variable.
- Dynamically add items to a list using a controller function.
- Create a controller to handle form submission and validate input fields.
- Use $scopeto bind a JSON object and display its properties.
- Implement a toggle functionality for an element.
Directives
- Create a custom directive that displays a “Hello World” message.
- Use the ng-initdirective to initialize variables.
- Create a directive that accepts an attribute and displays it dynamically.
- Use the ng-classdirective to conditionally apply CSS classes.
- Use the ng-styledirective to apply inline styles dynamically.
- Build a custom directive to display user profile information.
- Create a directive to render a list of items.
- Create a reusable directive for a navigation bar.
- Use the ng-repeatdirective with a custom filter.
- Use a directive to format phone numbers dynamically.
Filters
- Use the uppercasefilter to transform text.
- Use the currencyfilter to format a number as currency.
- Create a custom filter to reverse a string.
- Use the orderByfilter to sort an array dynamically.
- Filter a list of items based on user input.
- Create a filter to display only even numbers from a list.
- Chain multiple filters to transform data.
- Use the filterfilter to search within an array of objects.
- Create a custom filter to mask sensitive information (e.g., credit card numbers).
- Format a date dynamically using the datefilter.
Routing
- Set up basic routing with ngRoute.
- Create multiple views and navigate between them using links.
- Use $routeParamsto pass parameters to a route.
- Add a default route using otherwise.
- Create a 404 page for undefined routes.
- Use nested views with ng-view.
- Implement route guards using a custom service.
- Load a view dynamically based on user authentication status.
- Preload data for a route using a resolveproperty.
- Create a single-page application (SPA) with navigation and dynamic views.
Services and Dependency Injection
- Create a custom service to fetch data from a REST API.
- Use the $httpservice to perform a GET request.
- Use the $httpservice to perform a POST request and handle the response.
- Create a factory service to manage application state.
- Share data between controllers using a service.
- Implement a caching mechanism using $cacheFactory.
- Use $intervalto create a timer that updates every second.
- Create a weather app using an external API and $http.
- Handle errors in HTTP requests using $http’s.catchmethod.
- Build a shopping cart using a custom service to manage cart items.
Bonus Suggestions
For extended learning, you can:
- Create a form with validation for required fields, email formats, and more.
- Use $locationto dynamically update the browser URL.
- Implement authentication and session management.
- Create a dynamic dashboard with data fetched from APIs.
- Build a to-do app with persistent storage using localStorage or an external backend.