Skip to content

Instantly share code, notes, and snippets.

Last active April 19, 2018 13:28
What would you like to do?
Trigger HTTP Cloud Function via Angular Component (for transactional email)
<button (click)="sendEmail()">Send Email via Cloud Function</button>
/// SEE
/// To setup transactional email with sendgrid and firebase google cloud functions
import { Component } from '@angular/core';
import { Http, Headers, Response, URLSearchParams } from '@angular/http';
import 'rxjs/add/operator/toPromise';
selector: 'send-email',
templateUrl: './send-email.component.html',
styleUrls: ['./send-email.component.scss']
export class SendEmailComponent implements OnInit {
constructor(private http: Http) { }
sendEmail() {
let url = `https://your-cloud-function-url/function`
let params: URLSearchParams = new URLSearchParams();
let headers = new Headers({'Content-Type': 'application/json', 'Access-Control-Allow-Origin': '*' });
params.set('to', '');
params.set('from', '');
params.set('subject', 'test-email');
params.set('content', 'Hello World');
return, params, headers)
.then( res => {
.catch(err => {
Copy link

the header is showing error in that case but if we use like

return, params, headers)
return, params, {headers})

then its not showing error but also not working as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment