Skip to content

@bynary.composables.title

github-actions[bot] edited this page Nov 20, 2023 · 38 revisions

Module: @bynary/composables/title

Composables for managing the title of the page.

Table of contents

Functions

Functions

bindTitle

bindTitle<T>(value): T

Binds the value of the signal to the title of the page.

Type parameters

Name Type
T extends Signal<string>

Parameters

Name Type Description
value T The signal to bind to the title.

Returns

T

Example

@Component({
   selector: 'my-component',
   template: ''
})
class MyComponent {
    name = signal('Jane');

    constructor() {
        bindTitle(computed(() => `Hello ${this.name()}`));
    }
}

Defined in

title/src/title.composable.ts:24


useTitle

useTitle(initialValue?): WritableSignal<string>

A signal to change the title of the page.

Parameters

Name Type Description
initialValue? string The initial title of the page. Defaults to the current title of the page.

Returns

WritableSignal<string>

Example

@Component({
   selector: 'my-component',
   template: ''
})
class MyComponent {
    title = useTitle('Hello World'); // The title of the page is now 'Hello World'

    greetUser(name: string) {
        this.title.set(`Hello ${name}`); // For a name 'Jane', the title of the page is now 'Hello Jane'
    }
}

Example

Reading the current title of the page

@Component({
   selector: 'my-component',
   template: ''
})
class MyComponent {
    title = useTitle(); // The initial value of the signal is the current title of the page
}

Defined in

title/src/title.composable.ts:67

Clone this wiki locally