This Lesson is for Members

Subscribe today and get access to all lessons! Plus direct HD download for offline use, enhances transcripts, member comment forums, and iTunes "podcast" RSS feed. Level up your skills now!

Unlock This Lesson

Already subscribed? Sign In

Autoplay

    Generate components with the Angular CLI

    Mike BrocchiMike Brocchi

    Generating components with the Angular CLI allows for scaffolding applications quickly. Learn what will be generated for you and how to generate quickly with shortcuts in the desired directory.

    Code

    Code

    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    Transcript

    Transcript

    00:00 Type "ng generate component" to indicate that you want to generate a component. Then specify the name of the component. In this case I'll use "people" as the name of the component. In the code editor we see our new people folder that contains an empty style file, a simple HTML template file, the TypeScript component file, and a test file.

    00:21 Also notice that there have been five file changes made -- the four new files, as well as a change to the app.module file. The people component has been imported and declared with an app.module.

    00:33 As a shortcut, one generating component instead of typing out "ng generate component," there is a shorthand to type "ng," "g" for generate, "c" for component, and then the name of the component. These two statements will yield the same results.

    00:47 Type "ng g c people" to indicate the people folder and "person" as the name of the new component you wish to generate. As you can see by the generated output, the person component has been created underneath the people folder.

    01:01 The path you specify for generated and component is relative to the directory in which you are creating it. To create an address component underneath person, navigate it to the person directory which was just created. Once there, you can generate the address component.

    Discuss

    Discuss