And manually create a component reference component

Link components stored in the root components: https://cli.angular.io/

Generally, we want to customize components, for example, will be stored in a separate folder: components folder

Method one. New components folder in the app folder,

Method Two  Use the command to create ng g

1) cd to the project

2) Enter ng g will be some tips

3) ng g component components / news (news a new component)


 

Reference components:

This component is required, it is necessary before they can be referenced later using the root component

A way, if you are manually added to it , such as the need to reference in app_module.ts (the root component) can

For example: a new news assembly

References app.module.ts the import {newComponent} from './components/news/news.component'

    @NgModule configuration ({

      declarations: [newsComponent] added to it

  })

Second way: If the command is added to it, just going to be the root of the component view, whether to add the (usually automatically added without making add)

Check the name of the new component (similar to html tags), when introduced need to use


 

Check the component name:

In @Component news.component.ts assembly ({}) of the selector is connected to a component name:

@Component ({

  selector: 'component name', for example, a component name app-news

  templatenUrl:'',

  styleUrls[]

})

If the reference component in the root news component is used in the app.component.html

<app-news></app-news>

Content of the page or need to write in the corresponding component, that is written in the news, component.html in

Then enter the command ng serve --open run page

 

Guess you like

Origin www.cnblogs.com/rockyjs/p/11237117.html