Skip to content

@bynary.composables.title

github-actions[bot] edited this page Nov 23, 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.

This composable currently does not listen for changes to the title of the page made by other means. It will only set the title of the page, not read it.

Type parameters

Name Type
T extends Signal<string>

Parameters

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

Returns

T

The passed in signal (value parameter)

Example

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

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

Defined in

title/src/title.composable.ts:28


useTitle

useTitle(initialValue?): WritableSignal<string>

A signal to change the title of the page.

This composable currently does not listen for changes to the title of the page made by other means. It will only set the title of the page, not read it.

Parameters

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

Returns

WritableSignal<string>

A signal to change the title of the page.

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:75

Clone this wiki locally