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

Angular13 Contact Management Project from scratch, View Contact Details ...

Hello everyone! in this video, we will build an Angular Application like Angular 13 Contact management Application Project from scratch,angular contact management application, angular crud application, angular 13 project from scratch, angular 12 project from scrach, angular 11 project from scratch, angular project from scratch, angular with testycodeiz, angular project with testycodeiz, angular from testycodeiz, angular contact management app, angular crud project, angular crud project tutorial, angular tutorial with testycodeiz, Contact Management in angular #testycodeiz , #contactapp , #angular

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

complete python course in Hindi 2019 | Introduction to python for Beginn...

  #complete #python #course in #hindi #2019 | #introduction to #python for #beginners in #hindi | lesson 0,complete python course in hindi 2019,introduction to python for beginners in hindi | #lesson 0,introduction to python in hindi 2019,learn python in hindi 2019,python course in hindi by ashish mishra,python tutorial,python for beginners,best python tutorial,python course in hindi,learn python programming for beginners in hindi,learn python programming