AJS Notes - Unit-1
AJS Notes - Unit-1
ANGULAR JS
Unit-1
Why AngularJS?
HTML is great for declaring static documents, but it falters when we try to use it for declaring
dynamic views in web-applications. AngularJS lets you extend HTML vocabulary for your
application. The resulting environment is extraordinarily expressive, readable, and quick to
develop.
Alternatives: Other frameworks deal with HTML’s shortcomings by either abstracting away
HTML, CSS, and/or JavaScript or by providing an imperative way for manipulating the DOM.
Neither of these address the root problem that HTML was not designed for dynamic views.
Extensibility
AngularJS is a toolset for building the framework most suited to your application development.
It is fully extensible and works well with other libraries. Every feature can be modified or
replaced to suit your unique development workflow and feature needs. Read on to find out how.
Node.js: Node.js is a popular choice for building web applications for a number of reasons:
1. JavaScript Everywhere: It allows developers to use JavaScript on both the frontend and
backend, streamlining development and reducing the need to switch between languages.
2. Fast and Efficient: Powered by the V8 engine, Node.js executes JavaScript code at high speed,
making it ideal for applications requiring real-time interactions and high performance. Its non-
blocking, event-driven architecture handles concurrent requests efficiently, enabling scalability
and responsiveness.
3. Scalability: Node.js is designed to handle a large number of concurrent connections, making
it well-suited for building scalable applications that can handle growing user bases.
4. Large Ecosytem: Node.js boasts a vast package manager (npm) with a wide array of libraries
and modules, allowing developers to easily add functionalities and accelerate development.
5. Cost-Effective: Using JavaScript on both the frontend and backend can reduce the need for
specialized teams, leading to cost savings in development and maintenance.
6. Great for Real-Time Applications: Node.js is a natural fit for real-time applications like chat
applications, collaborative tools, and live dashboards due to its event-driven nature and
efficient handling of concurrent connections.
7. Easy to Learn: If you already know JavaScript, learning Node.js is relatively straightforward,
making it an accessible choice for developers.
When talking about Angular versions, it's important to distinguish between AngularJS (the
original framework) and Angular (the newer, completely rewritten framework).
AngularJS Versions:
1.8: The latest and final version of AngularJS, released in June 2020. This version is under Long
Term Support (LTS) until July 18, 2024.
Angular Versions:
19: The latest version of Angular, released in November 2024.
18: Released in May 2024, this version is under LTS.
17: Released in November 2023, this version is also under LTS.
AngularJS and Angular are different frameworks. Angular is a complete rewrite of
AngularJS, and they are not directly compatible.
AngularJS is in maintenance mode. While it is still supported, no new features are being
added.
Angular uses a different versioning scheme. Angular dropped the "JS" and started with
version 2.
Required Tools / Softwares to be installed
Why Node JS - Angular application written in Typescript cannot be opened in browsers.
Browsers only can understand javascript. By installing node js environment, Angular
application written in typescript can be converted to javascript. so that you can open in
browser.
Why Angular CLI
Angular command line interface. If you want to create angular application manually it takes
long time. CLI creates the project structure and arranges so that we can make
modifications/changes easily.
Why VS Code
Best editor for angular
Angular is popular front end frame work. It is popular Single Page Application (SPA's). i.e. once
page is loaded, it doesn't need to reload for every tab. It rather show all the tabs in the same
page.
Front End Frame Works
-React (Meta)
-Angular (Google)
-Vue (Evan You is creator)
Angular Features - A list of most important features and benefits of Angular:
Angular supports multiple platforms
Angular is a cross platform language. It supports multiple platforms. You can build
different types of apps by using Angular.
Desktop applications: Angular facilitates you to create desktop installed apps on
different types of operating systems i.e. Windows, Mac or Linux by using the same
Angular methods which we use for creating web and native apps.
Native applications: You can built native apps by using Angular with strategies from
Cordova, Ionic, or NativeScript.
Progressive web applications: Progressive web applications are the most common apps
which are built with Angular. Angular provides modern web platform capabilities to
deliver high performance, offline, and zero-step installation apps.
High Speed, Ultimate Performance: Angular is amazingly fast and provides a great
performance due to the following reasons:
Universal support: Angular can be used as a front-end web development tool for the
programming languages like Node.js, .Net, PHP, Java Struts and Spring and other servers
for near-instant rendering in just HTML and CSS. It also optimizes the website for better
SEO.
Code splitting: Angular apps are fast and loads quickly with the new Component Router,
which delivers automatic code-splitting so users only load code required to render the
view they request.
Code generation: Angular makes your templates in highly optimized code for today?s
JavaScript virtual machines which gives the benefits of hand-written code.
Productivity: Angular provides a better productivity due to its simple and powerful
template syntax, command line tools and popular editors and IDEs.
Powerful templates: Angular provides simple and powerful template syntax to create UI
view quickly.
IDEs: Angular provides intelligent code completion, instant errors, and other feedback
in popular editors and IDEs.
Angular CLI: Angular CLI provides command line tools start building fast, add
components and tests, and then instantly deploy.
Full Stack Development: Angular is a complete framework of JavaScript. It provides
Testing, animation and Accessibility. It provides full stack development along with
Node.js, Express.js, and MongoDB.
Testing: Angular provides Karma and Jasmine for unit testing. B y using it, you can check
your broken things every time you save. Karma is a JavaScript test runner tool created
by Angular team. Jasmine is the testing framework form unit testing in Angular apps,
and Karma provides helpful tools that make it easier to us to call our Jasmine tests whilst
we are writing code.
Animation Support: Angular facilitates you to create high-performance, complex
choreographies and animation timelines with very little code through Angular's
intuitive API.
Accessibility: In Angular, you can create accessible applications with ARIA-enabled
components, developer guides, and built-in a11y test infrastructure.
With just Node.js installed, you can work on a variety of JavaScript-based projects including:
simple web servers, command-line applications, basic web scraping tools, real-time
applications like chatbots, small APIs, data processing scripts, and prototypes for more complex
web applications by utilizing the extensive ecosystem of packages available through npm (Node
Package Manager) which comes bundled with Node.js; essentially, you can build the backend
logic for web applications without needing a separate server-side language.
Key points about working with only Node.js:
JavaScript is the primary language: You write code entirely in JavaScript, taking advantage of
its features for both front-end and back-end development.
npm packages: Access a vast library of packages through npm to add functionalities like
database interactions, file system manipulation, routing, and more to your projects.
Basic web server capabilities: Node.js includes built-in HTTP modules to create simple web
servers to serve static content or handle API requests.
Real-time applications: Node's event-driven architecture is well-suited for building
applications that require real-time updates, like chat systems or live dashboards.
To start with
First install Node js
Second install Angular CLI - at command prompt type : npm install -g @angular/cli
npm - node package manager (All Node js libraries are present in npm)
To check whether Angular CLI is installed or not
@cmd - type
ng --version
Now create new Project Application
go to project folder and the give the below command to create Angular Project Application
@cmd –type - ng new DemoApp or SampleApp
Now go to vscode editor
you can also do above command @ terminal in vscode
now check angularclasses for all the installed folders and filnpm install -g @angular/clies of the
project.
go to terminal and run the default project
go to the folder and type
ng serve
now it will compile and run in the server
copy the http://localhost:4200/ in browser and see the result
the code is present in app.component.html
to run in different port you have to type - ng serve -p <portno>
npm -version
node
>console.log("Hello");
Important files
index.html - complete project html file
main.ts - complete project type script file
styles.css - complete project css file
The above three files are global files.
app -
app.component.html
app.component.css
app.component.ts
app.module.ts
Important considerations:
Front-end development limitations:
While you can use Node.js for basic front-end tasks, for complex web interfaces, you'll
usually need to integrate a front-end framework like React, Angular, or Vue.js.
Database integration:
To work with databases, you'll need to install additional packages like Mongoose or
Sequelize depending on the database technology you choose.
Deployment considerations:
Deploying a Node.js application might require setting up a server environment
depending on the complexity of your project.
The Angular Framework, Angular CLI, and components used by Angular applications are
packaged as npm packages and distributed using the npm registry.
You can download and install these npm packages by using the npm CLI client, which is
installed with and runs as a Node.js® application. By default, the Angular CLI uses the
npm
client.
Download https://nodejs.org/en/
Then install and enter the following commands
D:\ajs\nodejs>cd..
D:\ajs>node -v
v16.17.0
D:\ajs>npm -v
8.15.0
Download Angular CLI:
https://angular.io/cli Here you can find below command
D:\ajs>npm install -g @angular/cli
Alternatively, you can use the yarn client for downloading and installing npm packages.
Both npm and yarn install the packages that are identified in a package.json file.
JavaScript AngularJS
Google developed it.
Netscape developed it.
It is a lightweight and object-oriented It is an open-source framework.
scripting language
It works on the model view controller (MVC)
It works on the concept of dynamic typing. concept for building apps.
A module in Angular acts as a container for a group of related features. It organizes code into
cohesive blocks, making the application easier to manage and scale. Modules encapsulate
components, services, directives, and pipes, and they define dependencies that other modules
need to operate. This organizational scheme allows for lazy loading—loading code only when
needed—which can greatly improve the performance of an application.
A component, on the other hand, is focused on the user interface. Each component controls a
part of the screen—a view—where Angular can render data and respond to user interactions.
A component consists of a template for the HTML, a class to handle data and logic, and metadata
that defines how the component fits into the view structure, such as its selector and the
template URLs.
Understanding the distinction and interplay between modules and components is crucial for
developing efficient Angular applications. Modules provide the framework that supports the
modular and scalable structure of an application, while components handle the details of
interacting with the user. Together, they create a powerful architecture that supports complex
and efficient web applications.
Angular components
Angular apps are built around components, which are Angular's building blocks. Components
contain the code, HTML layout, and CSS style information that provide the function and
appearance of an element in the app. In Angular, components can contain other components.
An app's functions and appearance can be divided and partitioned into components.
In Angular, components have metadata that define its properties. When you create your Own
Component, you use these properties:
A Sample Program
-------------------------
sample.html
-------------------------
<html>
<head> <title> LEIT PAGE</title> </head>
<body style="background-color: rgb(206, 239, 166);">
<h1>Lendi Institute of Engineering and Technology</h1>
<h2 class = solid>Care Character Career (CCC)</h2>
</body>
<hr style = "height:4px;background-color: red;">
<body style="background-color: antiquewhite;">
<p class = dotted >Addition of two no's: {{ 5 + 5 }}</p>
<p class = sample >Date:</p>
<div style = "height:10px"></div>
<form>
h2 { text-align: center; }
Output:
--------------------------
A shortcoming of MVC is that if we make any change in the view it doesn’t get updated
in the model. This problem was addressed in Angular2 by shifting to the MVVM architecture.
MVVM Architecture : it includes 3 things:
Model
View
View Model
The controller is actually replaced by View Model in MMVM design pattern. View Model is
nothing but a JavaScript function which is again like a controller and is responsible for
maintaining relationship between view and model, but the difference here is, if we updatem
anything in view, it gets updated in model, change anything in model, it shows up in view, which
is what we call 2-way binding.