Skip to main content

#3 Angular 8 tutorial in hindi | generate components and Component struc...

                 



How to create a Component in Angular 8

To create component in Angular we can use 
ng generate component "component name" command from Angular CLI.
Note:- you can do so : ng  g  c  user  –spec=false  ( it will not generate .spec file).
let’s see what this command is doing:
ng : stands for angular CLI object.
generate: is used to generate any file (you can also use g (short name) instead of generate).
component: it means we want to generate component(you can also use c(short name) instead of component).






Component Structure

Template :-  It is the view layout of the component , it tell the component what would be render for view
Class :-  It is component class that will have properties and methods that will use by view
MetaData:- This provide additional information to angular about component by Decorator, Metadata tells Angular how to process a class


#Class

In Angular we create  class like with class keyword followed by className (here it is infoComponent), here we have used export keyword that is ES6 module system. Export keyword here mark this class as public so that we can use it in other files by importing it .


#MetaData:-


Typescript class will not act like a Angular Component until we don’t attach additional information with metadata and to add metadata we use Decorators.

Decorators are the methods which start with @ symbol. So in this @Component is a decorator which is taking object ({} ) as argument which will allow us to pass metadata.

@Component() decorators will have lot of keys that will be used to define our component.


selector : selector key is used to define the tag name for the component . Now we can call app-user like a custom html tag "app-user" from any html template

templateUrl: Every Component will have a attached template that will work like a view . So whenever this component will render it will display view to the user and that view will come from this template file

styleUrls: Every Component have their own style that will come from file which you will mention in styleUrls. It takes array as value so we can pass multiple css files

@Component is a predefined decorator which we need to import from @angular/core library.



Comments

Popular posts from this blog

#2 Angular 8 Tutorial in Hindi | Project Structure and File Structure in...

                     Angular 8 File Structure e2e(end-to-end) – This folder contains test cases for testing the complete application along with its specific configuration files. node_modules – Contains all the node-modules used in the angular application. src – Complete source code of the application resides in src folder. app – root component of the application. assets – contains all the images or resources used in the application. environments – contains build configuration environments of the application. We can create any target environment and specify its configuration here. index.html – This is the main html page which is rendered when someone opens your website or application. main.ts – This is the main entry point of the angular application which compiles the AppModule and renders the specified bootstrap component in the browser. styles.css – Contains all the styles to be used as globally in the application....

Build Realtime Chat Application using Angular 13.

in this video, we will see Angular chat application, Angular chat app, angular 13 chat application, realtime chat application with angular, real-time chat application,build a chat app with node and socket.io, build a chat app with angular and socket.io,what's app chat functionality,building a chat application with angular node js and socket.io Angular chat application with testycodeiz,angular chat project from scratch, angular project from scratch, angular 13 chat application with testycodeiz, angular chat app with testycodeiz, angular with testycodeiz, agular project with testycodeiz #chatapp, #angularchat #testycodeiz

Angular 11 CRUD Application Using MEAN Stack,angular CRUD Example, Angul...

              Angular 11 CRUD Application Using MEAN Stack, angular CRUD Example, Angular crud project,angular crud tutorial,angular crud operation,angular crud application,angular crud with mean stack, #Angular11 ​ , #CRUD ​ , #Angularproject ​ ,