我使用beta7获得无限循环,这是Firefox的堆栈跟踪:
Error: Script terminated by timeout at:
DebugDomRenderer</DebugDomRenderer.prototype.createText@http: //localhost:2067/node_modules/angular2/bundles/angular2.dev.js:7184:11
viewFactory_t0@viewFactory_t:256:18
viewFactory_t0@viewFactory_t:266:1
viewFactory_t0@viewFactory_t:266:1
viewFactory_t0@viewFactory_t:266:1
viewFactory_t0@viewFactory_t:266:1
viewFactory_t0@viewFactory_t:266:1
...
在跳转到beta7之前一切正常,但如果我现在切换到beta6,我会得到同样的错误。所以我认为问题甚至在此之前就存在了。 正如您在AppComponent类中看到的,我正在处理2条路线:Main e NotFound。奇怪的是,如果我在浏览器中编写一个不存在的url(例如localhost:2056 / asdad),NotFound页面会正确显示。
我的包裹:
"angular2": "2.0.0-beta.7",
"systemjs": "0.19.20",
"es6-promise": "^3.0.2",
"es6-shim": "^0.33.3",
"reflect-metadata": "0.1.2",
"rxjs": "5.0.0-beta.2",
"zone.js": "0.5.15",
我的tsd:
{
"version": "v4",
"repo": "borisyankov/DefinitelyTyped",
"ref": "master",
"path": "typings",
"bundle": "typings/tsd.d.ts",
"installed": {
"jquery/jquery.d.ts": {
"commit": "9027703c0bd831319dcdf7f3169f7a468537f448"
},
"bootstrap/bootstrap.d.ts": {
"commit": "9027703c0bd831319dcdf7f3169f7a468537f448"
}
},
"ambientDependencies": {
"es6-shim": "github:DefinitelyTyped/DefinitelyTyped/es6-shim/es6-shim.d.ts#6697d6f7dadbf5773cb40ecda35a76027e0783b2"
}
}
我的靴子:
///<reference path="../../node_modules/angular2/typings/browser.d.ts"/>
import {bootstrap} from 'angular2/platform/browser'
import {AppComponent} from './app.component'
import {ROUTER_PROVIDERS} from 'angular2/router';
import {HTTP_PROVIDERS} from 'angular2/http'
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/retry';
bootstrap(AppComponent, [ROUTER_PROVIDERS, HTTP_PROVIDERS]);
我的路由类:
import {Component} from 'angular2/core';
import {RouteConfig, Router, Location, Instruction, ROUTER_DIRECTIVES} from 'angular2/router';
import {MainComponent} from './components/sections/main.component';
import {NotFoundComponent} from './components/sections/not-found.component';
import {EventEmitterService} from './services/event-emitter.service';
import {NavigationService, Routes} from './services/navigation.service';
@Component({
selector: 'my-app',
template: '<router-outlet></router-outlet>',
directives: [ROUTER_DIRECTIVES],
providers: [EventEmitterService, NavigationService]
})
@RouteConfig([
{path:'/' , name: Routes.Main , component: MainComponent, useAsDefault: true},
{path:'/not-found' , name: Routes.NotFound , component: NotFoundComponent}
])
export class AppComponent
{
public constructor(private _router: Router, _location:Location)
{
_router.recognize(_location.path()).then((instruction: Instruction) => {
if (!instruction)
_router.recognize('/not-found').then((instruction: Instruction) => _router.navigateByInstruction(instruction, true));
});
}
}
答案 0 :(得分:0)
经历了可怕的一天后,我发现了问题。
在编译.ts文件时使用Angular2。 beta6 ,您会收到以下错误。
为避免此类错误,建议在boot(main)类中使用以下代码行:
///<reference path="../../node_modules/angular2/typings/browser.d.ts"/>
这行代码删除了编译错误,但会在您打开应用程序时导致无限循环(确切地说,只有当组件包含两个或更多子组件时才会出现错误)
这是上面提到的编译错误(奇怪的是,即使你收到这个错误,网站也很棒):
node_modules/angular2/src/core/change_detection/parser/locals.d.ts(3,14): error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/change_detection/parser/locals.d.ts(4,42): error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/debug/debug_node.d.ts(14,13): error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/debug/debug_node.d.ts(24,17): error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/debug/debug_node.d.ts(25,17): error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/di/provider.d.ts(436,103): error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/di/provider.d.ts(436,135): error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/render/api.d.ts(13,13): error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/core/render/api.d.ts(14,84): error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/facade/collection.d.ts(1,25): error TS2304: Cannot find name 'MapConstructor'.
node_modules/angular2/src/facade/collection.d.ts(2,25): error TS2304: Cannot find name 'SetConstructor'.
node_modules/angular2/src/facade/collection.d.ts(4,27): error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/facade/collection.d.ts(4,39): error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/facade/collection.d.ts(7,9): error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/facade/collection.d.ts(8,30): error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/facade/collection.d.ts(11,43): error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/facade/collection.d.ts(12,27): error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/facade/collection.d.ts(14,23): error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/facade/collection.d.ts(15,25): error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/facade/collection.d.ts(95,41): error TS2304: Cannot find name 'Set'.
node_modules/angular2/src/facade/collection.d.ts(96,22): error TS2304: Cannot find name 'Set'.
node_modules/angular2/src/facade/collection.d.ts(97,25): error TS2304: Cannot find name 'Set'.
node_modules/angular2/src/facade/lang.d.ts(13,17): error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/facade/lang.d.ts(14,17): error TS2304: Cannot find name 'Set'.
node_modules/angular2/src/facade/lang.d.ts(78,59): error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/facade/promise.d.ts(1,10): error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/facade/promise.d.ts(3,14): error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/facade/promise.d.ts(8,32): error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/facade/promise.d.ts(9,38): error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/facade/promise.d.ts(10,35): error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/facade/promise.d.ts(10,93): error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/facade/promise.d.ts(11,34): error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/facade/promise.d.ts(12,32): error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/facade/promise.d.ts(12,149): error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/facade/promise.d.ts(13,43): error TS2304: Cannot find name 'Promise'.
node_modules/angular2/src/http/headers.d.ts(43,59): error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/http/url_search_params.d.ts(11,16): error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/platform/browser/browser_adapter.d.ts(75,33): error TS2304: Cannot find name 'Map'.
node_modules/angular2/src/platform/dom/dom_adapter.d.ts(85,42): error TS2304: Cannot find name 'Map'.
node_modules/rxjs/CoreOperators.d.ts(22,67): error TS2304: Cannot find name 'Promise'.
node_modules/rxjs/CoreOperators.d.ts(72,67): error TS2304: Cannot find name 'Promise'.
node_modules/rxjs/CoreOperators.d.ts(77,31): error TS2304: Cannot find name 'PromiseConstructor'.
node_modules/rxjs/CoreOperators.d.ts(77,54): error TS2304: Cannot find name 'Promise'.
node_modules/rxjs/Observable.d.ts(65,67): error TS2304: Cannot find name 'PromiseConstructor'.
node_modules/rxjs/Observable.d.ts(65,88): error TS2304: Cannot find name 'Promise'.
node_modules/rxjs/Observable.d.ts(72,84): error TS2304: Cannot find name 'Promise'.
node_modules/rxjs/Observable.d.ts(77,38): error TS2304: Cannot find name 'Promise'.
node_modules/rxjs/Observable.d.ts(100,66): error TS2304: Cannot find name 'Promise'.
node_modules/rxjs/Observable.d.ts(154,66): error TS2304: Cannot find name 'Promise'.
node_modules/rxjs/Observable.d.ts(159,31): error TS2304: Cannot find name 'PromiseConstructor'.
node_modules/rxjs/Observable.d.ts(159,54): error TS2304: Cannot find name 'Promise'.