【发布时间】:2016-10-06 20:06:36
【问题描述】:
我正在构建一个应用程序,它可以静态分析组件(来自 Angular 应用程序)并在 Angular 应用程序中呈现它们,这是一种样式指南,但在其中包含有关输入和组件其他方面的信息等的更多信息。
该应用程序使用 webpack 并分析一个组件并返回到一个“前端”(另一个 Angular 应用程序)关于一个组件的信息,包括它的源代码,我想在那个应用程序中呈现这个组件。
动态组件加载器要求您已导入组件并具有对它的引用(类型),我没有,因为此信息在运行时传递给应用程序。
我对如何渲染这个有点卡住了,angular2 是否有某种机制可以从字符串编译?使用某种代码生成,或者有更好的方法吗?
为了更清楚,我有:
{
"id": 0,
"name": "carte-blanche-angular2",
"kind": 0,
"flags": {},
"children": [
{
"id": 1,
"name": "\"component\"",
"kind": 1,
"kindString": "External module",
"flags": {
"isExported": true
},
"originalName": "node_modules/carte-blanche-angular2/tmp/component.ts",
"children": [
{
"id": 2,
"name": "NameComponent",
"kind": 128,
"kindString": "Class",
"flags": {
"isExported": true
},
"decorators": [
{
"name": "Component",
"type": {
"type": "reference",
"name": "Component"
},
"arguments": {
"obj": "{\n selector: 'cb-name', // <name></name>\n styles: [`\n div{\n color: red; \n font-style:italic;\n }\n `],\n // The template for our name component\n template: `\n <div>name : {{name}}</div>\n `\n}"
}
}
],
"children": [
{
"id": 4,
"name": "constructor",
"kind": 512,
"kindString": "Constructor",
"flags": {
"isExported": true
},
"signatures": [
{
"id": 5,
"name": "new NameComponent",
"kind": 16384,
"kindString": "Constructor signature",
"flags": {},
"type": {
"type": "reference",
"name": "NameComponent",
"id": 2
}
}
]
},
{
"id": 3,
"name": "name",
"kind": 1024,
"kindString": "Property",
"flags": {
"isExported": true
},
"decorators": [
{
"name": "Input",
"type": {
"type": "reference",
"name": "Input"
},
"arguments": {}
}
],
"type": {
"type": "instrinct",
"name": "string"
}
}
],
"groups": [
{
"title": "Constructors",
"kind": 512,
"children": [
4
]
},
{
"title": "Properties",
"kind": 1024,
"children": [
3
]
}
]
}
],
"groups": [
{
"title": "Classes",
"kind": 128,
"children": [
2
]
}
]
}
],
"groups": [
{
"title": "External modules",
"kind": 1,
"children": [
1
]
}
]
}
生成的 typedoc 是什么:
"{
"id": 0,
"name": "carte-blanche-angular2",
"kind": 0,
"flags": {},
"children": [
{
"id": 1,
"name": "\"component\"",
"kind": 1,
"kindString": "External module",
"flags": {
"isExported": true
},
"originalName": "node_modules/carte-blanche-angular2/tmp/component.ts",
"children": [
{
"id": 2,
"name": "NameComponent",
"kind": 128,
"kindString": "Class",
"flags": {
"isExported": true
},
"decorators": [
{
"name": "Component",
"type": {
"type": "reference",
"name": "Component"
},
"arguments": {
"obj": "{\n selector: 'cb-name', // <name></name>\n styles: [`\n div{\n color: red; \n font-style:italic;\n }\n `],\n // The template for our name component\n template: `\n <div>name : {{name}}</div>\n `\n}"
}
}
],
"children": [
{
"id": 4,
"name": "constructor",
"kind": 512,
"kindString": "Constructor",
"flags": {
"isExported": true
},
"signatures": [
{
"id": 5,
"name": "new NameComponent",
"kind": 16384,
"kindString": "Constructor signature",
"flags": {},
"type": {
"type": "reference",
"name": "NameComponent",
"id": 2
}
}
]
},
{
"id": 3,
"name": "name",
"kind": 1024,
"kindString": "Property",
"flags": {
"isExported": true
},
"decorators": [
{
"name": "Input",
"type": {
"type": "reference",
"name": "Input"
},
"arguments": {}
}
],
"type": {
"type": "instrinct",
"name": "string"
}
}
],
"groups": [
{
"title": "Constructors",
"kind": 512,
"children": [
4
]
},
{
"title": "Properties",
"kind": 1024,
"children": [
3
]
}
]
}
],
"groups": [
{
"title": "Classes",
"kind": 128,
"children": [
2
]
}
]
}
],
"groups": [
{
"title": "External modules",
"kind": 1,
"children": [
1
]
}
]
}"
这是我提到的字符串。
谢谢,
最好的问候 若昂·加林
【问题讨论】:
-
真的是动态组件加载的问题吗?还是动态路由的问题?
-
现在,解决方案绕过嵌入第一个应用程序(组件所属的应用程序)的包的 iframe。但是,是的,谈到动态加载和我认为可能 angular 有一些魔力可以获取一些代表组件的字符串并渲染它;Peheh