ContextService

ContextService TypeScript Class Reference

Overview

SERVICE This class is a "service" and it is automatically injected if declared as a member in the constructor of the consuming class. - See the constructor section below for details - See the Automatic Instance Injection page for details on the topic

The ContextService class provides methods to read and write pieces if information, which must be passed between views during the lifecycle of the current UI task. This class is used to exchange data between the views within the same task. When a new UI task is spawned, it also receives a brand new "context". The UI task "context" is a non-persistent memory space used to store temporary data and accessible from each view within the task.

No properties

▶️ get(key: string): Promise<any>

The get method returns the value stored under the key given as method argument.

▶️ set(key: string, value: string): Promise<void>

Method set stores a value for the given key. The value can be later read via the get method.

▶️ clear(): Promise<void>

The clear method clears all key-value pairs from the current UI task's context. All subsequent calls to method get will return undefined. This method is not likely to be needed in most of the cases as the task context is cleared automatically on each UI task completion.

How to use

import { View, ContextService } from '@dms';
import { Customer } from '@dms-bo';


@View()
export class MyView {

  constructor(private ContextService: ContextService);

  async load(): Promise<void> {      
    let  customer = await this.ContextService.get('customer') as Customer;
    console.log(`Customer name is ${customer.name}`);
  }

}

Last updated

Dynamics Mobile provided by Mobile Affairs Ltd. | 1712 Sofia, Bulgaria, Alexander Malinov 51 | sales@dynamicsmobile.com