unit5
unit5
Explain
Angular is a TypeScript-based open-source full-stack web application framework developed by
Google and Microsoft. It's a client-side framework used to build Single Page Applications (SPA) —
web apps that load a single HTML page and dynamically update it as the user interacts.
Angular is now one of the most popular open-source front-end web application frameworks
Angular is completely based on Components
It is completely written in Typescript & Developed by Google+Microsoft
Angular is a cross platform language. It supports multiple platforms. You can build different
types of apps by using Angular.
It is used to create Desktop applications,Mobile applications ,web applications.
Angular is amazingly fast and provides a great performance
Fast & Responsive – Updates only the changed part of the page.
Angular requires Node.js and npm (Node Package Manager) for installing packages and running the
project.
nginx
node -v
Add features
nginx
Check version:
css
ng --version
bash
ng <command> [options]
ng new my-app
This will:
cd my-app
code .
app.component.html – UI template
nginx
ng serve -o
http://localhost:4200
As you make changes in code, the server automatically reloads and reflects changes in the browser.
src/app/app.component.css – Styling
# OR
ng g c component-name
3. What are components & modules in Angular. How to create them. Explain.
Components
Components are the key features of Angular. The whole application is built using different
components. They make your complex application into reusable parts which you can reuse very
easily.
Angular is a SPA (Single Page Application) framework, and a view is made of one or more
components. An Angular component represents a portion of a view.
🔹 HTML Template
HTML template is a regular HTML file with additional Angular-specific syntax to communicate with
the component class.
Metadata is extra information used by Angular to run the component, such as:
selector
template URL
style URLs
It is defined using the @Component decorator.
ng g c <component-name>
Example:
ng g c greet
Modules
Modules are containers for related components, directives, pipes, and services.
It contains:
o Declarations of components
@NgModule({
declarations: [AppComponent],
imports: [BrowserModule],
bootstrap: [AppComponent]
})
Property Binding
Syntax:
<tag [property]="componentProperty"></tag>
Example:
<h1 [innerText]="title"></h1>
<button [disabled]="isDisabled">Click</button>
isDisabled = true;
✅ Attribute Binding
Used to bind HTML attributes that don't have DOM properties (e.g., aria-*, role, colspan,
data-*)
Uses: [attr.attributeName]="expression"
Syntax:
<tag [attr.attributeName]="value"></tag>
Example:
<p [attr.data-id]="itemId">Product</p>
itemId = 101;