SHARE
TWEET

Untitled

a guest Jun 20th, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @ViewChild('elementRef', {read: ElementRef}) elementRef: ElementRef;
  2.  
  3. // ..
  4.  
  5. get elementId() {
  6.   return this.type ? this.type + '-element' : null;
  7. }
  8.  
  9. ngOnInit() {
  10.   this.elementRef.nativeElement.id = this.elementId;
  11.   this._cd.detectChanges();
  12. }
  13.  
  14. ngAfterViewInit() {
  15.   this._element = this._stripeClientService.elements.create(this.type, this.options);
  16.  
  17.   setTimeout(() => {
  18.     console.log(document.getElementById(this.elementId));
  19.     this._element.mount(this.elementId);
  20.   }, 100);
  21.  
  22.  
  23.   this._element.on('change', (event) => {
  24.     const displayError = document.getElementById('errors');
  25.     if (event.error) {
  26.       displayError.textContent = event.error.message;
  27.       this.canSubmit = false;
  28.     } else {
  29.       displayError.textContent = '';
  30.       this.canSubmit = true;
  31.     }
  32.   });
  33. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top