顯然,角2.0.0需要將NgModule傳遞給UpgradeAdapter構造函數。我挖了從@角/更新下面的代碼片段,它的工作原理:
var adapter = new UpgradeAdapter(forwardRef(() => MyNg2Module));
var module = angular.module('myExample', []);
module.directive('greet', function() {
return {
scope: {salutation: '=', name: '='},
template: '{{salutation}} {{name}}! - <span ng-transclude></span>'
};
});
module.directive('ng2', adapter.downgradeNg2Component(Ng2));
@Component({
selector: 'ng2',
template: 'ng2 template: <greet salutation="Hello" [name]="world">text</greet>'
})
class Ng2 {
}
@NgModule({
declarations: [Ng2, adapter.upgradeNg1Component('greet')],
imports: [BrowserModule]
})
class MyNg2Module {
}
document.body.innerHTML = '<ng2></ng2>';
adapter.bootstrap(document.body, ['myExample']).ready(function() {
expect(document.body.textContent).toEqual("ng2 template: Hello world! - text");
});
不知道,如果你在你的代碼有這個其他地方,但你還需要從'進口{} forwardRef「@角/核心」;' –