将带有var对象的javascript文件添加到angular 6
文件中的对象如下所示:将带有var对象的javascript文件添加到angular 6,javascript,angular,Javascript,Angular,文件中的对象如下所示: var DATA = { "groups": [{ "id": "1", "name": "group xx", "devices": [{ "id": 11, "active": 1 }, { "id": 12, "active": 0 }, { "id": 13,
var DATA = {
"groups": [{
"id": "1",
"name": "group xx",
"devices": [{
"id": 11,
"active": 1
}, {
"id": 12,
"active": 0
}, {
"id": 13,
"active": 1
}, {
"id": 14,
"active": 0
}, {
"id": 15,
"active": 0
}, {
"id": 16,
"active": 1
}, {
"id": 17,
"active": 1
}]
}
显示的文件格式是JSONP。它在Angular中提供了一些支持,但不推荐使用它。更好的解决方案是在JSON文件中提供数据,并允许跨域访问数据(JSONP的最初原因)
如果您知道前导(
var DATA=
)是什么,接受全局变量的创建,并且知道安全含义,您还可以将文件包含在脚本元素中。问题是什么?