我是 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";
}
关于javascript - 是否可以在 angular2 之外设置变量 javascript 变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40111722/