Skip to content

Instantly share code, notes, and snippets.

@arutnik
Created November 5, 2017 20:01
Show Gist options
  • Select an option

  • Save arutnik/08fe705169fe879f9f708da10cd818c2 to your computer and use it in GitHub Desktop.

Select an option

Save arutnik/08fe705169fe879f9f708da10cd818c2 to your computer and use it in GitHub Desktop.
SFA Part 3: Calling Salesforce controller in Angular
import { SalesforceApiService } from './sf-api-service';
import { Component, OnInit } from '@angular/core';
declare var getSfApiWrapper : () => DataApi;
//Response information
export interface ApiStatus {
statusCode: number;
status: boolean;
code: string;
message: string;
method?: string;
}
//Callback function for the API call
export interface ApiHandler<T> {
(response: T, status: ApiStatus);
}
//Config options for making api call.
export interface CallConfiguration { buffer: boolean, escape: boolean, timeout: number }
const DEFAULT_CONFIG: CallConfiguration = { buffer: true, escape: false, timeout: 30000 };
//Interface of the JS wrapper provided by Salesforce
export interface DataApi {
helloAngular(name: string, callback : ApiHandler<string>, configuration : CallConfiguration) : void;
}
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
constructor(private _sfApi: SalesforceApiService) {
}
title = 'app';
ngOnInit() {
getSfApiWrapper().helloAngular("Fellow enthusiast", (result, status) => {
this.title = result;
}, DEFAULT_CONFIG);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment