尝试将Parent
和Ancestor
注释添加到 TypeScript 类型,所以我这样做了:
declare module "angular2/src/core/annotations_impl/visibility"{
function Parent():(target: any) => any;
function Ancestor():(target: any) => any;
}
使用任何一个注释都会抛出"TypeError: decorator is not a function".
我正在使用 alpha 22。
为什么我会收到此错误?
这是一个示例:
/// <reference path="typings/angular2/angular2.d.ts" />
import {Component,View,bootstrap} from "angular2/angular2"
import {Ancestor,Parent} from "angular2/src/core/annotations_impl/visibility"
@Component({
selector:"c"
})
@View({
template:`<p>{{app.message}}</p>`
})
class C{
app:App;
constructor(@Ancestor() app:App){
this.app = app;
}
}
@Component({
selector:"app"
})
@View({
template:`<c></c>`,
directives:[C]
})
class App{
message = "test";
}
bootstrap(App);
HTML:
<html>
<head>
<title>Angular 2 Quickstart</title>
<script src="https://github.jspm.io/jmcriffey/bower-traceur-runtime@0.0.89/traceur-runtime.js"></script>
<script src="https://jspm.io/system@0.16.7.js"></script>
<script src="https://code.angularjs.org/2.0.0-alpha.22/angular2.dev.js"></script>
<body>
<!-- The app component created in app.ts -->
<app></app>
<script>
System.import('app');
</script>
</body>
</html>