Erwin Erwin - 1 month ago 13
TypeScript Question

Is it possible to set variable javascript variables outside from angular2?

I am new to angular2 and used a component which is from other library and I want to pass a data from angular2 . My problem is that , I can't set the variable if its not from angular2 to that third party component.

Can anyone enlighten me if its possible?

Ex.

//hmtl outside angular2
somepage.html
var somevar; //variable on somepage.html

//component from angular2
export class SomeComponent implements OnInit{


constructor{
//id like to assign a value to somevar from inside this component
somevar = "blah blah";
}


}


Regards,
Erwin

Answer

hmtl outside angular2

window['SomeVarUpdated'] = function (newValue) {
  // do something
};

component from angular2

export class SomeComponent {
  constructor() {
    window['SomeVarUpdated']("blah blah");
  }
}
Comments