簡體   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