Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement