大网数据广告活动
Windows Server 管理

Add a module to a tool extension

· 52CE 我爱测

Develop a tool extension in Windows Admin Center SDK (Project Honolulu) - Add a module to a tool extension.

In this article, add an empty module to a tool extension we've created with the Windows Admin Center CLI.

Prepare your environment

If you haven't already done it, follow the directions in develop a tool (or solution) extension to prepare your environment and create a new, empty tool extension.

Use the Angular CLI to create a module (and component)

If you're new to Angular, we encourage you to read the documentation on the Angular website to learn about Angular and NgModule. See NgModule for guidance.

To learn more:

Open a command prompt, change directory to .\src\app in your project, and then run the following commands, replacing {!ModuleName} with your module name (spaces removed).

cd .\src\app
ng generate module {!ModuleName}
ng generate component {!ModuleName}
Value Explanation Example
{!ModuleName} Your module name (spaces removed) ManageFooWorksPortal

Example usage:

cd .\src\app
ng generate module ManageFooWorksPortal
ng generate component ManageFooWorksPortal

Add routing information

If you're new to Angular, we recommended you learn about Angular Routing and Navigation. The following sections define necessary routing elements that enable Windows Admin Center to navigate to your extension and between views in your extension in response to user activity. To learn more, see the Router guidance

Use the same module name that you used in the preceding step.

Add content to new routing file

  1. Browse to the module folder created by ng generate in the previous step.

  2. Create a new file {!module-name}.routing.ts, following this naming convention:

    Value Explanation Example filename
    {!module-name} Your module name (lower case, spaces replaced with dashes) manage-foo-works-portal.routing.ts
  3. Add this content to the file created:

    import { NgModule } from '@angular/core';
    import { RouterModule, Routes } from '@angular/router';
    import { {!ModuleName}Component } from './{!module-name}.component';
    
    const routes: Routes = [
        {
            path: '',
            component: {!ModuleName}Component,
            // if the component has child components that need to be routed to, include them in the children array.
            children: [
                {
                    path: '',
                    redirectTo: 'base',
                    pathMatch: 'full'
                }
            ]
    }];
    
    @NgModule({
        imports: [
            RouterModule.forChild(routes)
        ],
        exports: [
            RouterModule
        ]
    })
    export class Routing { }
    
  4. Replace values in the file created with your desired values:

    Value Explanation Example
    {!ModuleName} Your module name (spaces removed) ManageFooWorksPortal
    {!module-name} Your module name (lower case, spaces replaced with dashes) manage-foo-works-portal

Add content to new module file

  1. Open file {!module-name}.module.ts, found with the following naming convention:

    Value Explanation Example filename
    {!module-name} Your module name (lower case, spaces replaced with dashes) manage-foo-works-portal.module.ts
  2. Add content to the file:

    import { Routing } from './{!module-name}.routing';
    
  3. Replace values in the content just added with your desired values:

    Value Explanation Example
    {!module-name} Your module name (lower case, spaces replaced with dashes) manage-foo-works-portal
  4. Modify the imports statement to import Routing:

    Original value New value
    imports: [ CommonModule ] imports: [ CommonModule, Routing ]
  5. Make sure import statements are alphabetized by source.

Add content to new component TypeScript file

  1. Open file {!module-name}.component.ts, found with the following naming convention:

    Value Explanation Example filename
    {!module-name} Your module name (lower case, spaces replaced with dashes) manage-foo-works-portal.component.ts
  2. Modify content in the file to match the following example.

    constructor() {
        // TODO
    }
    
    public ngOnInit() {
        // TODO
    }
    

Update app-routing.module.ts

  1. Open file app-routing.module.ts, and modify the default path so it loads the new module you created. Find the entry for path: '', and update loadChildren to load your module instead of the default module:

    Value Explanation Example
    {!ModuleName} Your module name (spaces removed) ManageFooWorksPortal
    {!module-name} Your module name (lower case, spaces replaced with dashes) manage-foo-works-portal
        {
            path: '',
            loadChildren: 'app/{!module-name}/{!module-name}.module#{!ModuleName}Module'
        },
    

    Here's an example of an updated default path:

        {
            path: '',
            loadChildren: 'app/manage-foo-works-portal/manage-foo-works-portal.module#ManageFooWorksPortalModule'
        },
    

Build and side load your extension

You have now added a module to your extension. Next, you can build and side load your extension in Windows Admin Center to see the results.

Source: Microsoft Learn / Windows Server documentation by Microsoft and contributors (upstream author metadata: robinharwood). Documentation licensed CC BY 4.0. Code samples are covered by the MIT License. Converted from Markdown, with links normalized and embedded media omitted.

资料来源与适用范围

资料来源
Microsoft Learn / Windows Server documentation
适用范围
Windows Server · Source date 04/01/2023
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY 4.0 (documentation), MIT (code samples)

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。