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

发布于 6年前 浏览 17 更新于 3年前

Share

读取和管理共享数据。

AckShare (Service)

Methods

  • get(): Observable<any>: returns an Observable with the current shared data.
  • set(data: any): void: sets new shared data.

Example

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

import { AckShareModule, AckShare } from '@acknow-srl/share';

/**
 * 2. Add the module to your app imports.
 */

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

    /**
     * 3. Set some shared data.
     */

    constructor(private share: AckShare) {

        let data = [
            {
                name: 'Adam',
                surname: 'Smith'
            },
            {
                name: 'John Maynard',
                surname: 'Keynes'
            }
        ];

        this.share.set(data);
    }

}

/**
 * 4. In your components or services, read the shared data.
 */

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

import { AckShare } from '@acknow-srl/share';

@Component({
    ...
})
export class MyComponent {

    data: any;

    constructor(private share: AckShare) {
    }

    getSharedData() {
       return this.share.get().subscribe(data => {
           this.data = data;
       });
    }

}

Share

Reads and manages shared data.

AckShare (Service)

Methods

  • get(): Observable<any>: returns an Observable with the current shared data.
  • set(data: any): void: sets new shared data.

Example

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

import { AckShareModule, AckShare } from '@acknow-srl/share';

/**
 * 2. Add the module to your app imports.
 */

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

    /**
     * 3. Set some shared data.
     */

    constructor(private share: AckShare) {

        let data = [
            {
                name: 'Adam',
                surname: 'Smith'
            },
            {
                name: 'John Maynard',
                surname: 'Keynes'
            }
        ];

        this.share.set(data);
    }

}

/**
 * 4. In your components or services, read the shared data.
 */

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

import { AckShare } from '@acknow-srl/share';

@Component({
    ...
})
export class MyComponent {

    data: any;

    constructor(private share: AckShare) {
    }

    getSharedData() {
       return this.share.get().subscribe(data => {
           this.data = data;
       });
    }

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