30
loading...
This website collects cookies to deliver better user experience
git remote remove origin
ng serve
npm install -g firebase-tools
firebase login
firebase init
Hosting: Configure and deploy Firebase Hosting sites
, touch the space bar, and hit enter. Down-arrow to Create a new project
and hit enter. Give it a unique name (mps-split-ang-crud
shown below). Set dist/<your local app name>
for the public directory question.my-crud-app
. Enter n
for the question after that. See the images below for the settings described here.ng build --configuration production
firebase deploy
git remote add origin https://github.com/<your-user-name>/<your-repo-name>.git
git push -u origin master
language: node_js
node_js:
- "12.14"
branches:
only:
- master
before_script:
- npm install -g @angular/cli
script:
- npm install
- npm run build
deploy:
skip_cleanup: true
provider: firebase
token:
secure: ""
NOTE: For good reasons, the default branch of new projects on GitHub is main
. However, I struggled to get the project to deploy to Firebase properly when the branch was named anything other than master
. If you know how to deploy to Firebase on a different branch, please let us know!
firebase login:ci
NOTE : Travis is switching all endpoints from travis-ci.org to travis-ci.com. There is still a free tier. The Travis CLI still defaults to using the .org address, so the commands below are oriented toward ensuring that the CLI works with the .com address.
travis encrypt --add deploy.token <YOUR-FIREBASE-TOKEN> --com
.travis.yml
file, but the command above does everything in a single step..travis.yml
file and push it to your remote repo. That will trigger a build whose status you can follow on travis-ci.org. After the build succeeds, a deploy will be triggered. You can follow the deploy by going to Firebase.npm install --save @splitsoftware/splitio-browserjs
ng generate service splitio
to create a new service in the angular app.src/app/splitio.service.ts
:import { Injectable } from '@angular/core';
import { SplitFactory } from '@splitsoftware/splitio-browserjs';
import { fromEvent, Subscription } from 'rxjs';
@Injectable()
export class SplitIoService {
splitio: SplitIO.ISDK;
splitClient: SplitIO.IClient;
isReady = false;
treatments: SplitIO.Treatments;
subscription: Subscription;
features: string[] = [
'include_phone'
];
isTreatmentOn(treatmentName: string) : boolean {
let treatment = this.splitClient.getTreatment(treatmentName);
let result = null;
if (treatment == 'on') {
result = true;
} else if (treatment == 'off') {
result = false;
} else {
result = false;
}
console.log(`Value of: ${treatmentName} is ${treatment}`);
return result;
}
initSdk(): void {
this.splitio = SplitFactory({
core: {
authorizationKey: '<your api key>',
key: 'customer-key'
}
});
this.splitClient = this.splitio.client();
this.verifyReady();
}
private verifyReady(): void {
const isReadyEvent = fromEvent(this.splitClient, this.splitClient.Event.SDK_READY);
this.subscription = isReadyEvent.subscribe({
next() {
this.isReady = true;
console.log('Sdk ready: ', this.isReady);
},
error(err) {
console.log('Sdk error: ', err);
this.isReady = false;
}
});
}
getTreatments(): void {
this.treatments = this.splitClient.getTreatments(this.features);
}
}
SplitIoService
you just created.initSdk
gets the Split client set up. It uses your SDK client key. It calls verifyReady
verifyReady
uses the jsx event system and Split’s SDK_READY
event to indicate that the SplitIoService
is ready for actionisTreatmentOn
takes a string parameter, which is the name of a treatment, and it returns a boolean based on whether the treatment is on
or off
src/app/user/create/create.component.html
file and add the following code to it:<div *ngIf="splitService.isTreatmentOn('INCLUDE_PHONE')" class="form-group">
<label for="phone">Phone:</label>
<input formControlName="phone" id="phone" type="text" class="form-control">
</div>
*ngIf
calls the isTreatmentOn
function from the SplitIoService
, which determines whether the phone field will be rendered or not.