我期待从另一个模块以及窗口对象访问Angular 2组件.窗口对象仅用于在浏览器控制台中播放而不是实际用于生产(fyi).我以为我可以’导出默认类MyComponent’,但这似乎不起作用.我如何从另一个模块/窗口访问实例化的MyAppComponent类?
<body> <my-app></my-app> <script> System.import('ang').then(function (ang) { window.ang = ang; }); </script> </body>
…
import {Component,View,bootstrap} from 'angular2/angular2'; @Component({ selector: 'my-app' }) @View({ template: `<h1>Hello {{ count }}</h1><br>` }) class MyAppComponent { public count: number; constructor() { this.count = 0; } public increment(): void { this.count++; } } bootstrap(MyAppComponent);
然后想做这样的事情:
ang.increment();