Angular Client SDK
#
BackgroundAngular Client SDK ΠΏΠΎΠ²ΡΠΎΡΠ½ΠΎ ΠΈΡΠΏΠΎΠ»ΡΠ·ΡΠ΅Ρ ΡΡΠ΄ ΠΊΠΎΠ½ΡΠ΅ΠΏΡΠΈΠΉ javaScript.
Angular Client Π²ΠΊΠ»ΡΡΠ°Π΅Ρ Π² ΡΠ΅Π±Ρ:
- ΠΏΠ°ΡΠ°ΠΌΠ΅ΡΡΡ ΠΈΠ½ΠΈΡΠΈΠ°Π»ΠΈΠ·Π°ΡΠΈΠΈ ΠΈΠΌΠ΅ΡΡ ΡΠΎΡ ΠΆΠ΅ Π½Π°Π±ΠΎΡ ΠΏΠ°ΡΠ°ΠΌΠ΅ΡΡΠΎΠ², Π½ΠΎ ΡΠΏΠ΅ΡΠΈΡΠΈΡΠ½ΡΠΌΠΈ Π΄Π»Ρ angular.
- services
- ΠΏΠ°ΡΡΠ΅ΡΠ½ ΠΈΠ½ΡΠ΅ΠΊΡΠΈΡ Π·Π°Π²ΠΈΡΠΈΠΌΠΎΡΡΠ΅ΠΉ
#
ΠΠ½ΠΈΡΠΈΠ°Π»ΠΈΠ·Π°ΡΠΈΡ SDKΠΡ ΠΌΠΎΠΆΠ΅ΡΠ΅ ΡΡΡΠ°Π½ΠΎΠ²ΠΈΡΡ ΠΌΠΎΠ΄ΡΠ»Ρ Sigma ΡΠ΅ΡΠ΅Π· npm ΠΈΠ»ΠΈ yarn.
- NPM
- Yarn
npm install expf-sigma.js
yarn add expf-sigma.js
#
ΠΡΠΈΠΌΠ΅ΡΠΠ»Ρ ΡΠ°Π±ΠΎΡΡ sdk ΠΌΠΎΠΆΠ½ΠΎ Π½Π°ΡΡΡΠΎΠΈΡΡ ΠΎΡΠ΄Π΅Π»ΡΠ½ΡΠΉ services, ΠΊΠΎΡΠΎΡΡΠΉ Π±ΡΠ΄Π΅Ρ ΡΠΎΠ΄Π΅ΡΠΆΠ°ΡΡ Π½Π°ΡΡΡΠΎΠΉΠΊΠΈ sdk ΠΈ Π΄Π°Π½Π½ΡΠ΅ ΡΠΊΡΠΏΠ΅ΡΠΈΠΌΠ΅Π½ΡΠΎΠ², ΡΠΈΡΠ° ΡΠ»Π°Π³ΠΎΠ².
./src/app/services/sigma.services.js
import { Injectable } from '@angular/core;import Sigma from 'expf-sigma.js';
@Injectable({ providedIn: 'root'})
export class SigmaService { sigmaData: { title: string; buttonText: string; buttonColor: string; } = { title: '', buttonText: '', buttonColor: 'transparent' };
async getSigma() { const sigma = new Sigma(); const token = 'token'; sigma.init({ token, userData: { email: '1ex@mail.ru', custom: { cookieKey: '1', }, }, });
const browserName = await sigma.checkFlag('browser_name'); const buttonColor = await sigma.checkFlag('button_color'); const pay = await sigma .getExperiment('exp_name_pay') .then((res: { getFeatureValue: (arg0: string) => any }) => res.getFeatureValue('pay') );
this.sigmaData.buttonColor = buttonColor || 'red'; this.sigmaData.buttonText = pay || 'cache'; this.sigmaData.title = browserName; }}
Π Π΅Π·ΡΠ»ΡΡΠ°Ρ ΠΌΠΎΠΆΠ½ΠΎ ΠΏΠ΅ΡΠ΅Π΄Π°ΡΡ Π² Π»ΡΠ±ΠΎΠΉ ΠΊΠΎΠ½ΡΡΡΡΠΊΡΠΎΡ ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½ΡΠ° Π² Π²ΠΈΠ΄Π΅ ΠΈΠ½ΡΠ΅ΠΊΡΠΈΠΈ
./src/app/button/button.component.js
import { Component, OnInit,} from '@angular/core';
import { SigmaService } from '../services/sigma.services';
@Component({ selector: 'app-button', styleUrls: ['./button.component.css'], templateUrl: ` <button class="button" *ngIf="service.sigmaData?.buttonText" [ngStyle]="{ 'background': service.sigmaData?.buttonColor }" > {{ service.sigmaData?.buttonText }} </button> `,})
export class ButtonComponent implements OnInit { constructor(@Optional() public service: SigmaService) {}
ngOnInit(): void {}}