Angular 2 Final Release找不到名称模块 - moduleId:module.id

时间:2016-10-12 17:03:00

标签: angularjs angular

我刚刚从RC 4升级到Angular 2 Final Release,现在我的代码收到错误cannot find name 'module'

@Component({
    selector: 'dashboard',
    moduleId: module.id,
    templateUrl: 'dashboard.component.html',
    styleUrls: ['dashboard.component.css'],
    styles: ['.chart {display: block; width: 100%;} .title.handle{background-color:transparent;}']

})

有什么想法吗?

提前致谢!

更新,这是错误:

zone.js:355 Unhandled Promise rejection: Template parse errors:
Only void and foreign elements can be self closed "span" ("i role="presentation"><a role="menuitem" tabindex="-1" href="http://BruinAlert.ucla.edu">BruinAlert [ERROR ->]<span class="icon-external-link" /></a></li>
                                    <li role="presentat"): WidgetBankComponent@104:138
    Only void and foreign elements can be self closed "span" ("tion"><a role="menuitem" tabindex="-1" href="https://logon.ucla.edu/passchange.php">Change Password [ERROR ->]<span class="icon-external-link" /></a></li>
 at DirectiveNormalizer.normalizeLoadedTemplate (http://localhost:56159/node_modules/@angular/compiler//bundles/compiler.umd.js:13373:21)
    at eval (http://localhost:56159/node_modules/@angular/compiler//bundles/compiler.umd.js:13366:53)
    at ZoneDelegate.invoke (http://localhost:56159/node_modules/zone.js/dist/zone.js:203:28)
    at Zone.run (http://localhost:56159/node_modules/zone.js/dist/zone.js:96:43)
    at http://localhost:56159/node_modules/zone.js/dist/zone.js:462:57
    at ZoneDelegate.invokeTask (http://localhost:56159/node_modules/zone.js/dist/zone.js:236:37)
    at Zone.runTask (http://localhost:56159/node_modules/zone.js/dist/zone.js:136:47)
    at drainMicroTaskQueue (http://localhost:56159/node_modules/zone.js/dist/zone.js:368:35)
    at XMLHttpRequest.ZoneTask.invoke (http://localhost:56159/node_modules/zone.js/dist/zone.js:308:25)consoleError @ zone.js:355_loop_1 @ zone.js:382drainMicroTaskQueue @ zone.js:386ZoneTask.invoke @ zone.js:308
zone.js:357 Error: Uncaught (in promise): Error: Template parse errors:(…)consoleError @ zone.js:357_loop_1 @ zone.js:382drainMicroTaskQueue @ zone.js:386ZoneTask.invoke @ zone.js:308

2 个答案:

答案 0 :(得分:2)

更新问题后编辑:

您的HTML模板不正确,您有一个自我关闭的span元素,如下所示:

<span class="icon-external-link"></span>

HTML中不允许使用

将其更改为moduleId

编辑前:

您是否正在使用Webpack的最新angular-cli?如果是,则应删除所有{{1}}引用,因为此升级指南描述了:

https://github.com/angular/angular-cli/wiki/Upgrading-from-Beta.10-to-Beta.14

  
      
  1. 删除所有提及的moduleId:module.id。在webpack中,module.id是一个数字,但Angular期望一个字符串。
  2.   

答案 1 :(得分:0)

尝试删除它,然后应该为您应用中的所有组件执行此操作

@Component({
    selector: 'dashboard',
    templateUrl: 'dashboard.component.html',
    styleUrls: ['dashboard.component.css'],
    styles: ['.chart {display: block; width: 100%;} .title.handle{background-color:transparent;}']

})

<强> app.module.ts

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';

import { AppComponent } from './app.component';

import { DashboardComponent } from './dashboard-component/dashboard-component.component';


@NgModule({
    imports: [
        BrowserModule
    ],
    declarations: [
        AppComponent,
        DashboardComponent
    ],
    providers: [],
    bootstrap: [AppComponent],
})
export class AppModule { }