'epimss-personnel'给出以下内容......
@Component(
{
selector: 'epimss-personnel',
templateUrl: './personnel.component.html',
styleUrls: [ './personnel.component.css' ]
} )
export class PersonnelComponent implements OnInit {
personnel: IPersonnel = new Personnel();
constructor( ) {
}
ngOnInit() {
}
}
...如何以编程方式在PersonnelComponent中获取选择器字符串'epimss-personnel'?
当我添加尝试下面的建议时,我得到以下内容:
compiler.es5.js:14582 Uncaught Error: Unexpected value 'AppRoutingModule' imported by the module 'AppModule'. Please add a @NgModule annotation.
at syntaxError (compiler.es5.js:1503) [<root>]
at :4200/vendor.bundle.js:117324:44 [<root>]
at Array.forEach (<anonymous>) [<root>]
at CompileMetadataResolver.getNgModuleMetadata (compiler.es5.js:13953) [<root>]
at JitCompiler._loadModules (compiler.es5.js:25134) [<root>]
at JitCompiler._compileModuleAndComponents (compiler.es5.js:25093) [<root>]
at JitCompiler.compileModuleAsync (compiler.es5.js:25055) [<root>]
at PlatformRef_._bootstrapModuleWithZone (core.es5.js:4786) [<root>]
at PlatformRef_.bootstrapModule (core.es5.js:4772) [<root>]
at Object.426 (main.ts:47) [<root>]
at __webpack_require__ (bootstrap d227106…:52) [<root>]
at Object.1132 (main.bundle.js:7) [<root>]
at __webpack_require__ (bootstrap d227106…:52) [<root>]
at webpackJsonpCallback (bootstrap d227106…:23) [<root>]
...也不会显示用户界面。
答案 0 :(得分:0)
constructor(elRef:ElementRef) {
console.log(elRef.nativeElement.tagName);
}
答案 1 :(得分:0)
如果您不在组件内部,则将无法使用 this.locations = this.events.map(event => {
return new google.maps.Marker({ // added return here
position: {
lat: parseInt(event.latitude, 10),
lng: parseInt(event.longitude, 10)
},
map: this.map,
title: event.title
})
})
,并且ElementRef
解决方案也无法与AOT一起使用。幸运的是,当您知道目标是组件时,还有另一种选择:
Reflect