TypeError:Array.from不是函数

时间:2015-09-03 18:03:01

标签: javascript angular

我跟随Angular.io documenation写了一个简单的" Hello World"应用Angular 2.应用在浏览器中运行后,Angular 2会从TypeError引发angular2/src/browser_adapter.js

似乎所有东西都设置正确。知道问题是什么吗?

控制台:

TypeError: Array.from is not a function
    at createArrayFromMap (http://localhost:3000/node_modules/angular2/src/facade/collection.js:61:42)
    at Function.MapWrapper.values (http://localhost:3000/node_modules/angular2/src/facade/collection.js:100:47)
    at _createListOfBindings (http://localhost:3000/node_modules/angular2/src/di/injector.js:769:36)
    at Function.Injector.resolve (http://localhost:3000/node_modules/angular2/src/di/injector.js:403:16)
    at Function.Injector.resolveAndCreate (http://localhost:3000/node_modules/angular2/src/di/injector.js:420:41)
    at _createAppInjector (http://localhost:3000/node_modules/angular2/src/core/application_common.js:291:39)
    at http://localhost:3000/node_modules/angular2/src/core/application_common.js:257:31
    at Zone.run (http://localhost:3000/node_modules/angular2/bundles/angular2.js:118:17)
    at Zone.run (http://localhost:3000/node_modules/angular2/src/core/zone/ng_zone.js:165:42)
    at NgZone.run (http://localhost:3000/node_modules/angular2/src/core/zone/ng_zone.js:112:40)BrowserDomAdapter.logError @ :3000/node_modules/angular2/src/dom/browser_adapter.js:71

all.babel.js(符合es5 all.js):

import {Component, View, bootstrap} from 'angular2/angular2'

@Component({
  selector: 'helloworld'
})
@View({
  template: `<h1>Hello World!</h1>`
})
class HelloWorld {

}


bootstrap(HelloWorld)

的index.html:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Angular 2 Hello World</title>
    <script src="./node_modules/rx/dist/rx.all.js" charset="utf-8"></script>
    <script src="./node_modules/systemjs/dist/system.js"></script>
    <script src="./node_modules/angular2/bundles/angular2.js" charset="utf-8"></script>
    <script src="./dist/all.js" charset="utf-8"></script>
  </head>
  <body>
    <helloworld></helloworld>
     <script type="text/javascript">
      System.config({
        baseURL: '/'
      , defaultJSExtensions: true
      , paths:  {
          'angular2/*': './node_modules/angular2/*.js' // Angular
        , 'rx': './node_modules/rx/dist/rx.all.js'
        , 'all': './dist/all.js'
        }
      })

      System.import('all')
    </script>
  </body>
</html>

使用https://github.com/agconti/angular-2-hello-world进行复制。

1 个答案:

答案 0 :(得分:7)

为了让Angular 2在浏览器中运行,我必须包含traceur运行时:

<script src="https://github.jspm.io/jmcriffey/bower-traceur-runtime@0.0.87/traceur-runtime.js"></script>

即使在我将Systems.js配置设置为使用Babel作为转换器之后,这仍然是必要的。