@acknow-srl/title 中文文档教程

发布于 5年前 浏览 16 更新于 3年前

Title

允许您为您的应用程序配置一个通用标题,带有可选的可变部分。

AckTitleModule (Module)

Methods

  • forRoot(config: AckTitleConfig): void: configures the format for the title.

AckTitleConfig (Interface)

  • format (string): Title format. You can use {{TITLE}} placeholder to change the title variable part based on the page/route.

AckTitle (Service)

它在 root 中提供,因此它对整个应用程序可用。

Methods

  • get(): string: Returns the title.
  • set(title: string): void: Sets the title variable part, according to the configured format.

Example

/**
 * 1. Import the module and the configuration model in your main module (usually app.module.ts).
 */

import { AckTitleModule, AckTitleConfig } from '@acknow-srl/title';

/**
 * 2. Add the module to your app imports and configure it.
 */

// By using this format, {{TITLE}} will be the title variable part. Any component can override it using AckTitle.set() method.

const config: AckTitleConfig = {format: '{{TITLE}} - My app name'};

@NgModule({
  declarations: [
    AppComponent
    ...
  ],
  imports: [
    ...
    AckTitleModule.forRoot(config),
    ...
  ],
  bootstrap: [AppComponent]
})
export class AppModule {
}

/**
 * 3. Implement AckTitle service in your components.
 */

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

import { AckTitle } from '@acknow-srl/title';

@Component({
    selector: 'my-component',
    templateUrl: 'my-component.html',
    styleUrls: ['my-component.css']
})
export class MyComponent implements OnInit {

    constructor(private _title: AckTitle) {
    }

    ngOnInit() {

        // The content for the HTML <title> tag will be: 'My component title - My app name'.

        this._title.set('My component title');

    }

}

Title

Allows you to configure a common title, with and optional variabile part, for your apps.

AckTitleModule (Module)

Methods

  • forRoot(config: AckTitleConfig): void: configures the format for the title.

AckTitleConfig (Interface)

  • format (string): Title format. You can use {{TITLE}} placeholder to change the title variable part based on the page/route.

AckTitle (Service)

It is provided in root, so it is available to the whole app.

Methods

  • get(): string: Returns the title.
  • set(title: string): void: Sets the title variable part, according to the configured format.

Example

/**
 * 1. Import the module and the configuration model in your main module (usually app.module.ts).
 */

import { AckTitleModule, AckTitleConfig } from '@acknow-srl/title';

/**
 * 2. Add the module to your app imports and configure it.
 */

// By using this format, {{TITLE}} will be the title variable part. Any component can override it using AckTitle.set() method.

const config: AckTitleConfig = {format: '{{TITLE}} - My app name'};

@NgModule({
  declarations: [
    AppComponent
    ...
  ],
  imports: [
    ...
    AckTitleModule.forRoot(config),
    ...
  ],
  bootstrap: [AppComponent]
})
export class AppModule {
}

/**
 * 3. Implement AckTitle service in your components.
 */

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

import { AckTitle } from '@acknow-srl/title';

@Component({
    selector: 'my-component',
    templateUrl: 'my-component.html',
    styleUrls: ['my-component.css']
})
export class MyComponent implements OnInit {

    constructor(private _title: AckTitle) {
    }

    ngOnInit() {

        // The content for the HTML <title> tag will be: 'My component title - My app name'.

        this._title.set('My component title');

    }

}
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文