繁体   English   中英

是否可以在angular2之外设置变量javascript变量?

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

我是angular2的新手,并使用了来自其他库的组件,我想从angular2传递数据。 我的问题是,如果不是从angular2到该第三方组件,则无法设置该变量。

如果可能的话,有人可以启发我吗?

防爆。

//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";
}


}

问候,欧文

您可以分配给window ,然后再通过以下方式从其他任何地方访问它:

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

hmtl angular2外

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

来自angular2的分量

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM