Components in Angular


Components:
Component is a collection of htmls, css, type scripts etc, which displayed on browser. Whenever you create a component in Angular few default files will be created as below.

















Few files like app.module.ts are created by default in Angular application. If you open up the app.module.ts file, it has some libraries which are imported and also a declarative which is assigned the app component as follows



Add a New Component: You can add new component with command

ng generate component sharjeelswork

The following files are created in the sharjeels-work folder






















To register this component you need to mention this in Router inside app.module.ts file

Basically RouterModule.forRoot([{… }]) is an array which hold the route information for all component available in Angular application.























In this way you can run your component in browser. Just build your solution using command    ng build and serve the application using command ng serve.




ng serve This command will serve Angular application and run on port 4200 which is a default port for angular app. You can also change port no if required in case of running more than one app on same system.
ng serve –port 4201










Type http://localhost:4201 in your browser and press enter. After changes regarding router explained in earlier lines you can directly write the URL for newly created component.














In this way you can create a new component in angular application and use in any module of your application.



Happy Learning!!!


















Comments

Popular posts from this blog

Error : DependencyManagement.dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: com.adobe.aem:uber-jar:jar:apis -> version 6.3.0 vs 6.4.0

ERROR Exception while handling event Sitecore.Eventing.Remote.PublishEndRemoteEventException: System.AggregateExceptionMessage: One or more exceptions occurred while processing the subscribers to the 'publish:end:remote'

Dot Net Core Application Packaging using Octo