a web application or website that operates within a single web page. In traditional web applications, navigating to different pages involves full page reloads, while SPAs dynamically update parts of the page as users interact with it, without requiring a full page reload.
the process of determining which components or views to display based on the URL (Uniform Resource Locator) or route requested by the user. Since SPAs operate within a single web page, routing allows different "pages" or views of the application to be presented to the user without actually navigating to different HTML documents or triggering full page reloads.
SPA, certain URLs are associated with specific components or views within the application. For example, /home, /about, /products, etc., might correspond to different sections or pages of the SPA. • Client-side Routing: When a user navigates to a specific URL within an SPA (e.g., by clicking a link or typing in the address bar), the routing system intercepts this request on the client- side, typically using JavaScript. • Component Rendering: Based on the requested URL, the routing system determines which component or view should be rendered within the SPA's main container or viewport. This could involve showing or hiding different sections of the page, or dynamically loading content from the server. • History Management: SPAs use the browser's History API (e.g., pushState and replaceState) to manage navigation history without triggering full page reloads. This allows users to use the browser's back and forward buttons to navigate within the SPA.
such as React Router, Vue Router, or Angular Router, provide tools and APIs to manage routing seamlessly. These libraries allow developers to define routes, nested routes, route parameters, and transitions between different views. Lazy Loading: SPAs can also use routing to implement lazy loading, where components are loaded asynchronously only when needed. This helps improve initial loading times and reduces the amount of data sent to the client on the first request.
are self-contained, reusable building blocks that encapsulate a part of the user interface (UI) and its associated functionality. Each component typically represents a specific piece of the UI, such as a navigation bar, a form, a list of items, or a modal dialog.
promotes modularity, reusability, and maintainability of code. • Modularity: Components are modular units that can be composed together to build complex UIs. They isolate different parts of the UI and their functionality, making it easier to understand, test, and maintain code. • Reusability: Components are designed to be reusable across different parts of the application. Once defined, a component can be used multiple times in various contexts without needing to rewrite the code. • Encapsulation: Components encapsulate both the structure (HTML), presentation (CSS), and behavior (JavaScript) of a specific UI element. This encapsulation helps prevent conflicts between different parts of the application and promotes better code organization. • Composition: Components can be composed hierarchically, with smaller components nested within larger ones. This allows for the creation of complex UIs by combining simpler components together.
data between the model (application state) and the view (UI). It allows you to define a connection between the component's data and the HTML elements that display this data. There are several types of data binding in Angular
Interpolation: Interpolation is a one-way data binding from the component to the view. It allows you to embed expressions within double curly braces ( {{ }} ) in HTML templates, and Angular replaces these expressions with the corresponding component data. • Property Binding: Property binding is also a one-way data binding from the component to the view, but it binds an HTML attribute or property to a value in the component. It uses square brackets ( [ ] ). • Event Binding: Event binding is a one-way data binding from the view to the component. It allows you to listen to events raised by HTML elements (e.g., click, input) and call methods defined in the component class in response to these events. It uses parentheses ( ( ) ). • Two-way Binding: Two-way data binding provides a convenient way to bind the data in both directions, from the component to the view and from the view to the component. It uses the ngModel directive with banana-in-a-box syntax ( [(ngModel)] ). It's commonly used with form elements like input fields.
two or more applications or systems and facilitates communication or data processing between them. You can achieve similar functionality using Angular HTTP Interceptors for handling HTTP requests and responses. Interceptors allow you to intercept and modify HTTP requests and responses globally within your Angular application.
responses globally within your Angular application. They provide a way to apply common functionality such as logging, authentication, error handling, or modifying requests/responses before they are sent/received by the server/client.
design pattern that provides a simplified interface to a larger and more complex set of functionality. It hides the complexities of the underlying system and provides a unified interface for clients to interact with. In Angular, services are a way to organize and share code across your application. They are used to encapsulate functionality that doesn't belong in components, such as data access, logging, authentication, or communication with external services.
be used to simplify the interaction with multiple other services or APIs. It acts as an intermediary between components and the underlying services, abstracting away the details of how those services are accessed or composed.
Single-Page Applications (SPA) using Angular by Nishan Wickramarathna is licensed under CC BY 4.0 https://angular.io/tutorial/tour-of-heroes Homework Source code https://github.com/nishanc/Angular-SPA-Web-Modal