Conference Website: https://globaltechconferences.com/event/angular-virtual-conference-2021/
C# Corner - Community of Software and Data Developers: https://www.c-sharpcorner.com
C# Live - Dev Streaming Destination: https://csharp.live
#angular #webdevelopment #fullstack
Show More Show Less View Video Transcript
0:00
Hey everyone, thanks a lot for joining us and hope you are having a great time
0:06
That was an amazing session from Ankit and I saw the server side rendering from Shresti
0:12
and unit testing amazing talks and more talks coming after this. So please hang on and watch all the talks and we would love to actually hear about your
0:21
experience after the conference is over. So let's go ahead and get started
0:26
Let me just introduce myself. My name is Santosh Yadav and I'm one of the Google developer expert for Angular
0:32
And I'm one of the GitHub star. I'm an auto ambassador. Actually, I also write for in-depth.dev
0:39
This is learning and this is Angular. So, and apart from that, you can actually find me on all social media using this name
0:45
Santosh Yadav Dev. So, I also run the tech talks with Santosh, which Simon just mentioned
0:52
And apart from that, I'm doing a live stream on Twitch. So if you're interested, you can just find me on Twitch with the same user, same handle
0:58
Santosh Adav Dev. And I'm doing an Angular Getting Started live stream every Saturday, 6 to 8 p.m
1:05
Indian Standard Time. So anyone wants to learn Angular in more depth or it's not only for starters, it's even for
1:13
the experts. So feel free to join and come and chat, have a chat
1:18
So that's about me. Let's go ahead and get started and let's see how actually you can become productive using Angular
1:24
There will be a lot of content which is maybe expert developers already know, but yes, it's like how to get started and then how Angular can make you productive
1:35
So that's what we are going to cover. So first thing, Angular is actually built keeping productivity in mind
1:42
So it's not like, I mean, we are going to use some extra tools apart from one tool which I have as an what can surprise
1:50
So for you, but apart from that, whatever tool I'm going to mention is Angular
1:55
So I'm not going to give you any tool which is outside of Angular
1:59
So let's go ahead and get started. Generally, so as a developer, right
2:03
So when you start, when you start Angular, so what do you see? So this is the Angular, like when you think, okay, this is just Angular
2:09
But let me tell you what actually Angular is. Angular is this apart from one logo, which I'm sure a lot of developers can identify
2:16
which is not supported anymore in Angular 12. But apart from that, every logo which you can see is actually part of Angular
2:24
So let's see each one of them and let's get started with what we are going to see
2:29
and what Angular already has. So it has built-in module for forms
2:34
So if you go to any other technology, you have to actually go ahead and search for different libraries, which form to use, which form not to use
2:40
Angular already has taken care of it from the day when. So we are, of course, going to see that built-in module for routing
2:46
You don't have to search for routing. Pre-configured unit testing. It comes with Jasmine and Karma
2:52
Great session from Jitendra was already there. Ability to build tools. So a lot of frameworks and libraries
2:59
are actually building the tools based on Angular. So if you see, Ionec is one
3:04
Mike is also one of the team members of Ionec and they are using Angular tools
3:09
which I'm going to mention a lot. And then you have built-in support for PWA
3:14
You don't have to actually go ahead and be an expert to actually create a PWA in Angular
3:20
So we'll also see that. SSR and pre-rendering, you already learned more about SSR from the session by SRUSTY
3:28
Built-in support for localization and internationalization, if I'm not wrong. And built-in support for dependency injection
3:36
This is one of the great feature which actually puts Angular in a separate bucket apart from
3:43
all the frameworks which we have. And then it also has its own Angular material component library
3:47
So and many more. So let's go ahead and get started. So whenever you have a new project, the of course, the best
3:54
the first criteria is we should be able to release faster. I mean, we should be able to develop faster
4:00
So let's see how you can actually get started with Angular. So there are four commands by using which you can start a new project
4:06
and then you can start you can deploy your app. How cool is that? Right
4:10
And what if I tell you that you have an Angular CLI and you just still have to use Angular CLI
4:16
all four commands inside Angular CLI and you are done. You created your application, you added some code and then you deployed it
4:23
So NBMI, Angular CLI, so this is the first step. So by using which you can install NBMI, sorry, you can install Angular CLI
4:30
Then you can create a new app by using NG New and then you can give an app name and your app is created
4:36
Then to serve the application, of course, you have to test it locally, right? So what you can do is ng-serve and then your application will be started on localhost and then you can test it
4:47
And then finally, you can build the application using ng-build-fn-prod. So you get a bundle which can be deployed on production
4:55
And finally, just do ng-deploy. So Angular CLI has the built-in support for ng-deploy where you have multiple providers
5:04
In case anything is missing, feel free to add. I mean, it's a community-driven project
5:08
So you have right now support for Azure, AWS, Firebase, Netlify, GitHub pages and many more
5:14
So that's about CLI. And the next thing, when you start with some front end projects or front end library
5:21
the another learning curve is templates. React has JSX, who has who.js
5:27
What about Angular? So Angular is just HTML. It's not that you have to learn a new language
5:32
So it's like you have three ways to actually work with templates
5:36
First is string interpolation. So let's say you have any variable which you want to display in your template, which is still HTML
5:42
I'm not asking you to write a separate JSX or VueJS extension
5:48
I mean, of course, they are great as well, but still HTML, right? I mean, I'm not learning a new template engine
5:53
So you can create a variable, just render them using string interpolation into your HTML and that's done
5:58
You can also use property binding, which is my favorite feature, of course, because you can do a lot of stuff with property binding
6:04
And that's how you can actually give a box any valid property name
6:10
Remember this this is really important for the new learners that any valid property name can be used for property binding So you have any variables you want to bind it to any valid property of any HTML tag
6:22
That's done. So just put a box and that's it. And then you have button
6:27
Sorry, you have events, right? So of course, if you create an enterprise word application, you
6:31
are going to work with a lot of events, maybe your click events or drop down different events
6:37
Right. So what do you in that case? So of course, you can just use this is bananas in tax, which we
6:42
call it as so you can see click equals to function so you can just still HTML
6:46
you're writing just HTML right so this is just a deco ration which you are
6:50
doing for example for to work with property binding you are putting a box and to work with events you are just doing a banana syntax dependency
6:59
injection as I said one of my favorite feature and one of the most useful
7:03
feature in angular which actually keeps it in another league of frameworks so
7:09
So what dependency injection is? Most of the .NET developer and Java developers are actually aware of what dependency injection is because we use it a lot, right
7:18
We, because I used to be a .NET developer. I have written .NET code for like eight to nine, eight years
7:25
Yeah, eight years. And then I love dependency injection. That was amazing feature
7:29
But what in Angular? What's in Angular, right? So in Angular, you don't have to configure anything
7:34
That's really cool, right? I mean, in Angular or Java, you have to go and use some other libraries, configure it, and then you can use it
7:42
Di is out of box in Angular. So what you can do is you can create classes
7:46
I'm sure everyone knows classes. And then it comes with an injectable decorator
7:51
So here, so let's say this product component, right? So this is a class
7:56
And then you can inject a class using constructor injection. In case you are a .NET or Java developer, you know two ways
8:02
I'm sure property injection and then you have constructor injection. So here we are using constructor injection and then you can start using all the methods
8:10
which are actually available in that particular class. It also comes with the concept of injection token
8:17
So by using which you can actually go ahead and do a lot of stuff. Here I have given an example how you can actually use local storage
8:24
which is a native API of your browser, but inject it as a service inside your code
8:29
That's possible because of dependency injection. So let's move on and then forms. As I said, Angular comes with forms. You don't have to worry about
8:39
which form to choose. Of course, there is one problem that those forms are not type safe and
8:44
it's been a long pending feature, but still forms are really useful and there are some
8:50
libraries which are available to actually make your forms strictly type. But Angular team is
8:56
working on that. So you have two types of forms in Angular, which is one is template driven forms and
9:02
Another is we'll see that. Right. So to use template driven forms, you have forms module
9:07
You can just import forms module and you get all the functionality, which
9:11
template driven form offers. And then you can use it. What about reactive forms
9:15
So reactive forms has a separate module, which is known as reactive forms module
9:19
You can just import it and then start using the features of it. If you if you are wondering which one is best, just go ahead and try both
9:28
So probably maybe reactive forms is best for you or maybe template driven is best for you
9:34
My personal choice has been reactive forms for a long time, but never know
9:39
So this is how you can actually create a form. So this is a reactive form approach where you have a form
9:44
Of course, this is how you create a form in HTML, right
9:48
You go anywhere and this is the way you will be creating a form
9:51
So you have form and then this form group is actually you're saying, okay, this is my
9:55
form name and we are still doing submit. else. I mean, I just told you, right? So it's HTML, that's it. Template is nothing fancy
10:04
So, and then you have form control names, some form control names, which we have created
10:08
and then you just submit the form and that's it. And let's move on. And routing. What about routing
10:14
I mean, what in case my application is very large, I have a lot of navigation around
10:19
So what we can do, of course, Angular comes with routing. So you can just quickly set up your routes
10:24
by using this syntax so you have routes array and then inside that you have two properties path and
10:30
component and good thing about routing which i have seen is this syntax is almost similar in react
10:37
and wo as well i mean this is even if you're transitioning from react or wo you will not find
10:42
any difference right so you have still path and component syntax which is already available here
10:47
you have to actually uh provide your all paths all routes using uh router module dot for root and
10:53
for child so in case you have child modules and then you can you just use router link
11:00
and then provide the route on which you want to navigate based on which link you click and then
11:06
don't forget router outlet this is the biggest mistake when i still make it so whenever i'm
11:12
doing live coding i still miss router outlet and then just bang my head around that what's wrong
11:18
Okay, but what in case we have a large application, right? So what's there
11:23
I mean, of course I cannot serve and do MB application and I can tell my clients that, okay, this is
11:30
this will work perfectly fine. Probably, yes, in case it is an internal application
11:35
and no one cares about the internet bandwidth, right? Because in large organization, you have a good infra
11:41
but what in case one day everyone starts working from home and they don't have good infra to work with
11:46
So let's lazy load. Right. So you can actually split your code into multiple chunks and that
11:52
holds that possible. Yes, that's possible using routing. So what you can do is you can have separate modules and then you can use this
11:59
syntax load children and then start lazy loading the modules. Angular team is working on a new API where you will be able to actually lazy
12:07
load your components, but it's it will be in future. It's in roadmap
12:12
So definitely it will happen one day. but meanwhile you can actually lose a load based on your modules
12:19
API calls, of course, every large enterprise application may need an API call, right
12:25
So how to do that? That possible right I mean of course you can just go ahead and use Axios or you can just use Fletch API which is native Or if you are old school you can just go ahead and use XML Just joking Don use it
12:43
Angular has solution for this. So it's known as known as HTTP client module
12:48
So you can just use HTTP client module and then it gives you all the services to work with your API calls
12:55
So what you can do is inject the HTTP client module, then inject the HTTP client service
12:59
And then it gives you access to all the methods of REST APIs. I mean, most of you already know REST APIs in case you are not
13:07
So it is a server-side code which will be hosted at a certain endpoint
13:12
And then you have several methods like get post, put delete. So HTTP client is something which will give you access to all those methods
13:19
And then you can just give HTTP.get and just pass your API
13:24
Great introduction. I mean, so there was a great session from Ankit previously
13:28
So you might have learned something about HTTP there as well. But yeah, this is how it is possible
13:32
You can just include HTTP client module and that's it. Now, let's move on to another use case
13:38
So you have a large enterprise, right? And you have many teams, many teams
13:44
and they are using different technologies. Someone is using React, someone is using VOO
13:49
someone is using just vanilla JS, or someone is using, let's say, Stansil, right
13:54
So how about creating an Angular component which can be used across any platform or any framework
14:01
So yes, Angular does support creating web components. What you have to do is you have to just do ng-add Angular elements and then give the project name, whatever project name you have
14:11
And then this is the code. It gives you an API called create custom element, which you can find here
14:17
find here so you have create custom element API which can convert your component to a custom
14:23
element which you can go ahead and use anywhere in any framework go to react go to go to stencil
14:29
go to anywhere right so even in your vanilla js and that's how you can actually use it the only
14:35
problem right now is you have to use angular module which is a little bit painful but let's see
14:41
let's see so create pws so now your manager comes one day or your client comes one day and says
14:48
hey look what we uh i can see a lot of people are talking about pws let's do that i mean uh how can
14:55
we do it like uh next day and you will be like oh my god that that should be pain right i mean i have
15:01
to learn pwa first and then i have to implement it you don't have to inside your angular app so
15:06
So you can just do ng add angular PWA. Most of the configuration is already done for you
15:11
Doesn't it make you productive, right? So yes, it does. So now let's move on to another feature, another amazing feature
15:18
Localization. So over the years, everyone has their business growing up and there are no boundaries now
15:27
So same business actually having same website is actually selling in across the world
15:31
what in case they have to maintain 20 different websites for different 20 different languages
15:37
that would be pain right so how angler can help you here so it has something called localization
15:44
so which is available you can just do ng add angler localize and these are the things so you
15:49
have to extract all the files you have to actually convert all the files manually that's but there
15:54
are three formats which are supported and which is a industry standard as well so you have xcliff
15:59
which is default and xcliff2 and xmb. So these are three support, three file formats, which are supported natively by Angular itself
16:09
Angular localization, but you can, you already have many libraries available for localization
16:13
international, internationalization. So go ahead and feel free to explore what you need. Yeah
16:20
And then unit testing. Of course, there was a great introduction for unit testing by Jitendra
16:25
So it comes with zero configuration effort. You don't have to do any configuration to actually set up your unit testing
16:31
It comes with Karman, Jasmine, and then you can just do ng test to run test cases
16:36
Of course, you have to write it. So don't forget about that. So now let's say your client comes again and says, Hey, what about SSR
16:44
Right? So the project which we have built or the product which we have built
16:49
it doesn't look like it's an SEO compliant because I am missing a lot of things
16:54
My application is not coming on top whenever I search. So how we can do that or how we can actually reduce the initial load time
17:04
And then he says, I have heard something about SSR because Rusty said this in the C-Shop Corner conference
17:13
So you say, okay, now I have to go ahead and learn SSR
17:17
You don't have to. I mean, sure, Rusty already informed you about this. So you can just do NG ADD, NG Universal Express Engine
17:23
and then you get everything which is required to actually convert your applications to SSR and
17:30
What it does so it does configures SSR with Express server provides dev server with live reload for SSR
17:36
So you can actually run it manually and check if it works fine or not Provides pre-rendering functionality as well in case you want to pre-render some pages. Yes, that's possible
17:45
Now let's go above that right. So you have let's say five different apps and
17:51
And now the problem is you have to actually go ahead and copy paste a lot of code in different five apps
17:58
And your manager says, look, we need a solution for this. We cannot just keep copy pasting our entire code
18:04
So he says, let's build libraries. And then you are like, okay, now how to build Angular libraries
18:11
So you don't have to worry about it. Angular has taken care of you. So what you can do is you can just do ng generate a new library and give a library name
18:18
So what you can do, so you can create and publish libraries, It provides the ng-packager configuration which is needed to actually compile your libraries and publish it and you can also use it inside the app
18:29
which you probably never have to actually publish it in case you are just using it inside monorepo
18:35
You can share the code across multiple applications or libraries. Both are possible. This is how you do it
18:41
So you could say any generate library name and then you can build a library by giving a library name and
18:46
and if and prod flag in case you want to publish it in case you are just using it in mono repo i think it absolutely fine if you skip plot flag And then you can just go inside the distributable folder which will be created after build
18:59
And then you can just publish it and then publish. Of course, you have to log in and create your own account
19:04
In case your organization is using JFrog and any internal IT factory, you have to actually give the path where you want to publish it
19:13
But what about the errors, right? I mean, you will be getting a lot of errors in, in
19:18
while writing code or while building code. What if I have to see all those code at runtime? That's a waste of time
19:25
So let's see how Angular makes you productive here. So Angular has Angular compiler, which is really awesome. So let's see
19:32
So what you can do, so you can debug your template, you can debug and test your component. You can come
19:36
you can actually get all the errors while actually doing ng-serve or ng-build
19:42
I mean 90% of errors you will actually get it here 10% probably
19:47
maybe it is related to dependency injection because that's something which is resolved at runtime and
19:53
This is how it helps you right? So here you can see I am trying to use a property called in a text, which is not a valid property
20:00
So what if I see this error at runtime? You best of my time
20:04
Angular gives you this error inside the VS code as well as once you do ng-serve
20:08
So you can actually quickly resolve it and then move on. Right. You can also debug your code, debug your components
20:16
So here there is an example where I'm trying to actually get hold of one of the
20:21
component and then I'm trying to assign a new value or any property to this
20:26
particular object. So here you can see I have $0 which is of course created by
20:31
Chrome team. So you can use this in any framework or library
20:36
So here I'm taking the access to list components by using API called ng
20:42
So I'm passing ng.getComponent$0. So whatever component is selected, I'm getting the access
20:48
And then you can see I'm getting all the properties of to-do list component. And then you can just change the value
20:54
So I'm updating here to blank just to see if it was fine or not
20:58
And then you can just call ng.applyChanges. And that's it. You can actually test your components in browser
21:04
I mean, you should be doing end-to-end testing and unit testing, but this is even cooler, right
21:09
So you can actually do it here. So let's move on. There are a few more APIs which we have
21:14
But what about IntelliSign support? I mean, one of the biggest problems when I moved from .NET to Angular was actually
21:24
okay, how to get the IntelliSign support in VS Code because .NET spoiled us, right
21:29
I mean, we always look for IntelliSign support. And that's also possible using Angular language service
21:35
So whenever you start with Angular, I would suggest go ahead and install Angular language service
21:39
So the advantage is all the errors, even without compiling, you will get it inside the VS code
21:45
So if you have any types issue or any variables which does not exist, get the error inside the VS code and just resolve it without actually compiling your application or even doing the production build
21:57
and it actually prompts you with all the APIs which exist. So you don't have to search for those
22:07
Angular material and CDK. So what in case you want to build your own component library
22:11
or you need an UI library and let's say you decided to use material design
22:17
Yes, Angular comes with that, but it's a separate project, but still maintained by Angular
22:22
So what you can do is you can just use Angular material. It's a UI library managed by Angular team
22:26
you can actually create your own components using CDK and it is optimized and well tested for protection use
22:33
So go ahead and feel free to use it. And this is how you can do it. So you can just do NGA add and the material and that is done
22:41
Now, so you did everything. Now, there is a new tool, let's say Playwright
22:48
So it's an E2E tool, which is available for writing end-to-end test cases. and your manager says, let's use Playwright because it looks like a cool project to me
22:58
And you have to actually go ahead and configure everything by your own
23:02
And it will be a pain every time, right? So whenever you hand it over to other developers
23:08
what in case you just build a tool on top of Playwright and make it part of Angular CLI
23:14
Yes, that's possible. So you have two things which is available. One is one API is known as
23:19
schematics where you can automate creation modification or adding any extra files to your
23:25
workspace and you can also automate setup for your library in Angular so that's two things
23:30
I mean of course there are more things which you can do with schematics but I just wanted to keep
23:34
it short here and then you have builders so you can just overwrite the angular build process and
23:39
let's say if you want to use playwright right as an end-to-end test cases yes you can do that using
23:45
builders and you can bring your own tool that's any framework is doing it and
23:49
even a next dev tools is doing it a lot of builders are available even there are
23:54
builders for Cypress want to be super productive this is this is this is the
24:01
surprise which I have so yes if you want to be super productive just go ahead and
24:05
do ng add normal slash workspace which will migrate your angular CLI workspace
24:09
to Narwal workspace and thank me later. So that's it. But there are two websites which I want to
24:17
show you probably if it gets loaded. Let's see. Yeah. So one is ngx.tools where you can actually
24:24
find a lot of schematics like release and packages. And another is angularbuilders.dev
24:31
where you can actually go ahead and find a lot of custom builders which is already created by
24:35
community so you don't have to create your own of course we try to avoid it as much as possible
24:40
right so just go ahead and search it on custom builders.dev and yeah and these are the some
24:45
references in case you want to get started with angular you have angular.io you have dev.2 this
24:50
is angular then dev.2 angular and intep.dev these are my go-to resources in case you want to learn
24:56
learn more about Angular and that's it for the day. Thanks a lot
#Programming
#Development Tools


