这是完整的错误。

RangeError: Maximum call stack size exceeded
at Injector._instantiate (http://localhost:8000/build.js:36366:63)
at Injector._instantiateProvider (http://localhost:8000/build.js:36244:23)
at Injector._new (http://localhost:8000/build.js:36234:21)
at InjectorInlineStrategy.instantiateProvider (http://localhost:8000/build.js:35998:30)
at ElementDirectiveInlineStrategy.init (http://localhost:8000/build.js:35106:20)
at new AppElement (http://localhost:8000/build.js:34800:24)
at viewFactory_constructor0 (viewFactory_constructor:74:26)
at viewFactory_constructor0 (viewFactory_constructor:76:1)
at viewFactory_constructor0 (viewFactory_constructor:76:1)
at viewFactory_constructor0 (viewFactory_constructor:76:1) <app id="NG2_UPGRADE_0_app_c0">

这是我的源文件。
import 'reflect-metadata'

import {Component} from 'angular2/core';
import {bootstrap} from 'angular2/platform/browser'

console.log('Files have started being compiled and infinite loop has begun');

var TodoCmpTest =
Component({
  selector: 'todo-cmp'
})
.View({
  template: `<h1>TodoCmpTest</h1>`
})
.Class({
  constructor: function(){
    console.log('hello');
  }
});


var AppComponent =
Component({
  selector: 'app',
})
.View({
  template: `
  <div>
  <h1> Hello World </h1>
  <todo-cmp></todo-cmp>
  </div>
  `,
  directives: [TodoCmpTest]
// directives: []
})
.Class({
  constructor: function () {}
});

bootstrap(AppComponent);

一遍又一遍地恢复了TodoCmpTest。

如果您交换这两行,它将起作用,但不会加载TodoCmpTest。directives: [TodoCmpTest]// directives: []
您可以通过执行以下操作来重现此错误...
1. git clone https://github.com/danielrasmuson/Angular2HelloWorld-StackOverflow2. use node v5.4.03. jspm install4. npm install5. npm start

最佳答案

在beta 1中,似乎是个 Angular 2问题,
我尝试使用 Angular 为2 beta 0的 repo 协议(protocol),它工作正常,没有循环。
我建议您坚持使用beta 0,直到他们修复它为止。
我不知道jspm,所以这是我要测试的内容:(可能不需要这里的所有内容,只需要编辑package.json->删除->并重新安装就可以继续安装我的beta 1版本)

将package.json angular2依赖项编辑为:

"jspm": {
    "dependencies": {
      "angular2": "npm:[email protected]",
      "reflect-metadata": "npm:reflect-metadata@^0.1.3"
    },

然后我跑
rm -rf jspm_packages/npm/[email protected]
jspm install npm:[email protected]
npm start

关于javascript - 组件初始化无限循环-Angular 2 JSPM,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34755607/

10-11 12:10