我想在我的Angular2應用升級Angular1成分和使用它的「使用從角2碼角1個組件配置」下的下列the official Angular2 documentation here,但它提供了以下錯誤:
error_handler.js:54 TypeError: Cannot read property 'get' of undefined
at ChartDirective.UpgradeComponent (upgrade_component.js:97)
。
當線97上仔細檢查,這個檢查$未定義:
我的代碼是非常簡單的:
import { Directive, ElementRef, Injector } from '@angular/core';
import { UpgradeComponent } from '@angular/upgrade/static';
export const coolComponent = {
template: 'cool',
controller: function() {
}
};
@Directive({
selector: 'app-chart'
})
export class ChartDirective extends UpgradeComponent {
constructor(elementRef: ElementRef, injector: Injector) {
super('coolComponent', elementRef, injector);
}
}
我對引導main.ts是:
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app.module';
platformBrowserDynamic().bootstrapModule(AppModule);
這是問題的簡化版本,以最少的再現步驟: https://github.com/dolanmiu/angular2-upgrade-test
它生成angular-cli
它仍然無法使用!相反,我得到一個錯誤,說應用程序不是自舉的。有道理,因爲你告訴我刪除'AppModule'中的'bootstrap'行[Screenshot here](http://imgur.com/a/7o3Bi) – Dolan
遵循Angular網站的指示,我還實現了'ngDoBootstrap'方法。這應該擺脫你的錯誤。 –