Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
560 views
in Technique[技术] by (71.8m points)

core ui - Adding new components with default layout

I have just downloaded the angular admin template. Then i add a new component:

ng g n test

When I navigate to the component, the default layout is not applied. I guess it uses the app.component layout. How do you tell the component it should use the default UI?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

to add a new componet follow these steps:

  1. create a component-name-routing.module.ts file
  2. create a component-name.module.ts file
  3. create a component-name.component.html file
  4. create a component-name.component.ts file

component-name.component.ts file:

import { Component, OnInit, Input } from "@angular/core";

@Component({
    selector: 'app-componentName',
    templateUrl: './component-name.component.html',
})

export class NameComponent implements OnInit {}

component-name-routing.module.ts file

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';

import { NameComponent } from "./component-name.component";

const routes: Routes = [
  {
    path: '',
    component: NameComponent,
    data: {
      title: 'route title'
    },
    children: [
      {
        path: '',
        redirectTo: ''
      },
    ]
  }
];

@NgModule({
  imports: [RouterModule.forChild(routes)],
  exports: [RouterModule]
})

export class ComponentNameRoutingModule {}

component-name.module.ts file

// Angular
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';

// Theme Routing
import { ComponentNameRoutingModule } from "./component-name-routing.module";

import { ComponentNameComponent } from "./component-name.component";

@NgModule({
    imports: [
        ComponentNameRoutingModule,
    ],
    declarations: [
        ComponentNameComponent
    ]
 })
 export class ComponentNameModule {
     constructor() {}

 }

all this in a new folder in the views directory and you'll be good to go.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...