0

以下是从 angularjs 2 es6 模板http://goo.gl/IGaTZw开始的 plunker 我添加了 traceur 并删除了 main.es6.js 替换为 main.js 以防隐式模式受到干扰。

<head>
<script data-require="traceur-runtime@0.0.88" data-semver="0.0.88" src="https://cdn.rawgit.com/google/traceur-compiler/d3d0553de3315398a956dc2f9edd6a982d786b0a/bin/traceur-runtime.js"></script>
<script src="https://jspm.io/system.js"></script>
<script src="https://code.angularjs.org/2.0.0-alpha.30/angular2.dev.js"></script>
</head>    

<body>
<app></app>
<script>System.import('main');</script>
</body>

Main.js-----

import {
  ComponentAnnotation as Component,
  ViewAnnotation as View, bootstrap
} from 'angular2/angular2';

@Component({
  selector: 'app',
  viewInjector: [Service]
})
@View({
  template: '{{greeting}} world!'
})
class App {
  constructor(service: Service) {
    this.greeting = service.greeting();
    setTimeout(() => this.greeting = 'Howdy,', 1000);
  }

}

class Service {
  greeting() {
    return 'Hello';
  } 
}

bootstrap(App);

我尝试在本地下载脚本文件,但在那里也失败了。我不能使用 npm 等,因为我的笔记本电脑有问题。

提前谢谢了。

4

1 回答 1

0

要纠正,包括跟踪选项:

 System.config({
   traceurOptions: {
     annotations: true
 }

,(注释是实验性的,必须手动打开)添加

import { Inject } from 'angular2/di';

并更改 App 构造函数参数

constructor(@Inject(Service) service).

只要将 types:true 添加到 traceur 选项,构造函数构造函数(服务:服务)中的类型似乎也可以省略注入注释。

于 2015-07-31T10:57:50.600 回答