所以我在一个Angular2项目上使用webpack2,该项目有几个外部依赖项.其中一些依赖项使用commonjs并声明如下组件:
@Component({
moduleId: module.id,
templateUrl: 'mycomponent.html'
...
})
Run Code Online (Sandbox Code Playgroud)
这会导致以下错误:
Error: moduleId should be a string in "MyComponent"
Run Code Online (Sandbox Code Playgroud)
经过一些研究,我发现这是因为Webpack期望组件将id作为数字,而Angular将其声明为字符串.我无法更改依赖关系代码.我能做些什么才能忍受这种依赖?
谢谢!
这是一个研究案例:
<html>
...
<embed name="foo">
<embed name="bar">
...
</html>
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用Watir Ruby的API引用名为"bar"的embed元素.该元素由Chrome的DOM Inspector显示,但我无法使用Watir的任何查找方法找到它:
browser.embeds() # only <embed name="foo"> is found
browser.html.include? 'bar' # => false
Run Code Online (Sandbox Code Playgroud)
为什么会这样?为什么Watir没有显示完整的HTML?如果我有不同帧中的元素或由Javascript init函数动态插入,是否可以使用Watir访问它们?
谢谢
我一直在尝试动态创建一个组件并将其附加到文档标记.我一直很难搞清楚如何选择正文的ViewContainterRef,所以我可以使用ComponentFactoryResolver添加一个新组件.
我尝试使用下面的代码获取对body容器的引用,但它不起作用.有谁知道怎么做?谢谢!
import {
Component,
ComponentRef,
ApplicationRef,
Injector,
Input,
ViewContainerRef,
ComponentFactoryResolver,
ViewChild,
OnInit,
OnDestroy
} from '@angular/core';
import {
ModalComponent
} from './modal.component';
@Component({
selector: 'my-modal'
})
export class MyModalComponent {
private _bodyRef: ViewContainerRef;
constructor(private resolver: ComponentFactoryResolver, private app: ApplicationRef) {
// Does not work!
this._bodyRef = app['_rootComponents'][0]['_hostElement'].vcRef;
}
ngOnInit() {
// Calls the factory to crate a brand new instance
let componentFactory = this.resolver.resolveComponentFactory(ModalComponent);
this._bodyRef.createComponent(componentFactory);
}
}
Run Code Online (Sandbox Code Playgroud)