在将 angular2
项目升级到 RC5 时,我遇到了一个大问题。将所有代码减少到最少以调试问题,但没有找到它的根源。我的应用程序的每个请求都会导致以下错误消息(浏览器中的开发人员控制台):
EXCEPTION: Error in ./e class e_Host - inline template 0:0
ORIGINAL EXCEPTION: The selector "ng-component" did not match any elements
我的简化代码如下所示,我相信这是最基本的代码:
main.ts
///<reference path="../node_modules/typescript/lib/lib.es6.d.ts"/>
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AdminModule } from './component/admin/admin.module';
platformBrowserDynamic().bootstrapModule(AdminModule);
admin.module.ts
import {NgModule} from '@angular/core';
import {BrowserModule} from '@angular/platform-browser';
import {TestComponent} from '../admin/test/test';
@NgModule({
declarations: [TestComponent],
providers: [],
imports: [BrowserModule],
bootstrap: [TestComponent],
})
export class AdminModule {
}
test.ts
import {Component} from '@angular/core';
@Component({
//templateUrl : 'public/component/admin/test/test.html',
template: '<h1>Hello World!</h1>',
directives: []
})
export class TestComponent {}
我对每条路径进行了两次和三次检查,并包括了它的有效性,到目前为止一切都很好。
我的 npm
设置是这样的:
package.json
{
"name": "Angular2Boilerplate",
"version": "0.1.0",
"description": "Angular2Boilerplate",
"main": "index.js",
"scripts": {
"test": "gulp test"
},
"dependencies": {
"@angular/common": "2.0.0-rc.5",
"@angular/compiler": "2.0.0-rc.5",
"@angular/core": "2.0.0-rc.5",
"@angular/forms": "0.3.0",
"@angular/http": "2.0.0-rc.5",
"@angular/platform-browser": "2.0.0-rc.5",
"@angular/platform-browser-dynamic": "2.0.0-rc.5",
"@angular/router": "3.0.0-rc.1",
"@angular/router-deprecated": "2.0.0-rc.2",
"@angular/upgrade": "2.0.0-rc.5",
"angular2-localstorage": "^0.3.0",
"systemjs": "0.19.27",
"es6-promise": "^3.0.2",
"es6-shim": "^0.33.3",
"reflect-metadata": "^0.1.3",
"rxjs": "5.0.0-beta.6",
"zone.js": "^0.6.12",
"primeng": "^1.0.0-beta.8",
"primeui": "^4.1.12"
},
"devDependencies": {
"browser-sync": "^2.10.0",
"del": "^2.2.0",
"gulp": "^3.8.11",
"gulp-clean": "^0.3.2",
"gulp-concat": "^2.6.0",
"gulp-debug": "^2.0.1",
"gulp-inject": "^1.2.0",
"gulp-rimraf": "^0.1.1",
"gulp-sass": "^2.1.1",
"gulp-sass-glob-import": "^0.1.0",
"gulp-sourcemaps": "^1.5.1",
"gulp-tslint": "^1.4.4",
"gulp-typescript": "^2.5.0",
"gulp-uglify": "^1.5.1",
"superstatic": "^3.0.0",
"typescript": "^1.8.10"
},
"keywords": [
"angular2",
"typescript",
"sass",
"gulp"
],
"author": "André Kirchner",
"license": "MIT"
}
尝试了我能想到的一切来找出问题所在,但现在我需要你的帮助。有谁知道什么地方出了这么大的问题?
最佳答案
你错过了selector
在你的字段 TestComponent
你需要在你的 index.html
中使用那个组件因为它是您正在引导的那个。当我删除 <my-app>Loading...</my-app>
时,我刚刚在我的项目中对其进行了测试来自 index.html
,我得到完全相同的错误:
关于javascript - 异常 : Error in ./e 类 e_Host - 内联模板 0:0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39203779/