Created
November 5, 2017 20:01
-
-
Save arutnik/08fe705169fe879f9f708da10cd818c2 to your computer and use it in GitHub Desktop.
SFA Part 3: Calling Salesforce controller in Angular
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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