Created
February 10, 2018 18:19
-
-
Save Frelseren/525ba46b74ff3af27b958b349889f7cf to your computer and use it in GitHub Desktop.
Angular app LCC Web Service
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 { Component, OnInit, ChangeDetectorRef } from '@angular/core'; | |
import * as LCC from 'lightning-container'; | |
declare const sforce; | |
interface Contact { | |
Id: string; | |
Name: string; | |
} | |
@Component({ | |
selector: 'app-contacts', | |
templateUrl: './contacts.component.html' | |
}) | |
export class ContactsComponent implements OnInit { | |
contacts: Contact[]; | |
constructor( | |
private cd: ChangeDetectorRef | |
) {} | |
ngOnInit() { | |
sforce.connection.sessionId = LCC.getRESTAPISessionKey(); | |
try { | |
this.contacts = JSON.parse(sforce.apex.execute('AngularPOC', | |
'getContacts', {})); | |
/** | |
* Angular cannot detect changes made by lightning container by itself, | |
* so we have to force the update manually. | |
*/ | |
this.cd.detectChanges(); | |
} catch (e) { | |
console.error(e); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment