0

I am trying to add a typescript property called this.data using the executescript() method of the InAppBrowser plugin but the property returns undefined instead of 'testdata'.

I don't know if this is applicable or not or if i am doing something wrong.

import { Component } from '@angular/core';

import { NavController, LoadingController, NavParams} from 'ionic-angular';
import { InAppBrowser } from '@ionic-native/in-app-browser';


@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {

  browser: any;
  data = 'testdata';

  constructor(
    public navCtrl: NavController,
    public navParams: NavParams,
    public iab: InAppBrowser
  ) {}

        showIAB(){
                this.browser = this.iab.create('http://example.com/','_blank','location=no,toolbar=yes,zoom=no,hardwareback=no,EnableViewPortScale=yes,closebuttoncaption=Done')
                this.browser.on('loadstop').subscribe(
                  ev =>{
                    this.browser.executeScript({
                      code: `document.getElementById('username-1202').value = this.data;
                      document.getElementById('user_password-1202').value = '123456';`
                    })
                  },
                  err =>{

                  }
                )

}

1 Answer 1

2

Your are not injecting this.data properly into the template string, replace with ${this.data}

{ code: `document.getElementById('username-1202').value = '${this.data}';
document.getElementById('user_password-1202').value = '123456';`}

If you do the way you are doing, the "this.data" will take the context of your new window, not the original one.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.