Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular2异常:必须定义标记_Angular - Fatal编程技术网

Angular2异常:必须定义标记

Angular2异常:必须定义标记,angular,Angular,app/boot.ts import {bootstrap} from 'angular2/platform/browser'; import {AppComponent} from './app.component'; bootstrap(AppComponent); app/app.component.ts import {Component} from 'angular2/core'; @Component({ selector: 'my-app', template: '{{t

app/boot.ts

import {bootstrap} from 'angular2/platform/browser';
import {AppComponent} from './app.component';
bootstrap(AppComponent);
app/app.component.ts

import {Component} from 'angular2/core';
@Component({
  selector: 'my-app',
  template: '{{title}}'
})
class AppComponent {
  title: "app"
}
错误:

EXCEPTION: Token must be defined!
STACKTRACE:BrowserDomAdapter.logError @ angular2.dev.js:23514
ExceptionHandler.call                 @ angular2.dev.js:1147
(anonymous function)                  @ angular2.dev.js:14801
NgZone._notifyOnError                 @ angular2.dev.js:5796
collection_1.StringMapWrapper.merge.onError @ angular2.dev.js:5700
run                                   @ angular2-polyfills.js:141
(anonymous function)                  @ angular2.dev.js:5719
NgZone.run                            @ angular2.dev.js:5681
ApplicationRef_.bootstrap             @ angular2.dev.js:14906
bootstrap                             @ angular2.dev.js:25054
execute                               @ boot.ts:4
u                                     @ system.src.js:4597
execute                               @ system.src.js:4597
y                                     @ system.src.js:4597
...

这是另一个多次抓住我的错误。我忘记(再次)导出我的根组件。应该是:

export class AppComponent {

如果我花时间更仔细地查看堆栈跟踪(而不是搜索StackOverflow,而不是找到确切的问题),我会注意到它引用了我编写的一个文件,
boot.ts:4

,在我的情况下,这是因为在下一行末尾有分号:

import {Component} from 'angular2/core';

我必须确保AppComponent被传递到main.ts中的引导函数中:

bootstrap(AppComponent);

确保您有所有这些条目,同时检查输入错误应用程序而不是AppComponent等

应用程序组件.ts

export class AppComponent {
  name: string;

  constructor() {
    this.name = "World";
  }
}
import {bootstrap}    from 'angular2/platform/browser';
import {AppComponent} from './app.component';

bootstrap(AppComponent);
main.ts

export class AppComponent {
  name: string;

  constructor() {
    this.name = "World";
  }
}
import {bootstrap}    from 'angular2/platform/browser';
import {AppComponent} from './app.component';

bootstrap(AppComponent);

我从我的一个测试规范文件中收到了这条消息,因为在同一个规范文件的底部定义了一个模拟服务,只是将它移到了顶部(在测试定义之前),现在一切都按预期工作

我也遇到过这个问题。在我的例子中,这是因为Augury扩展,它是抛出的,因为我有Angular 2.1.3,它支持2.3.0及以上版本。

在我的例子中,TestBed.get()是一个错误 我使用了错误的依赖项名称作为参数

let xyzService;

xyzService = TestBed.get(xyzService);

//Changing the above statement with xyzService = TestBed.get(XYZService); worked

这是一个非常愚蠢的错误xD

自从发布候选版本以来,他们已经改变了这一点。现在是:
import{Component}来自“@angular/core”更重要的是,我在一个before钩子中注入的服务上有一个拼写错误,在修复之后,事情继续工作。