我正在尝试使用我的一些Ionic1 Angular服务创建新的Ionic2应用程序。我已阅读https://angular.io/docs/ts/latest/guide/upgrade.html并知道我应该使用UpgradeAdapter但由于某种原因它不起作用。
这是我的app.ts
文件引导Ionic2应用程序:
// This is to tell TS that `require` method is in fact available
declare function require(name:string);
import { Component, Inject } from '@angular/core';
import { ionicBootstrap } from 'ionic-angular';
import { HTTP_PROVIDERS } from '@angular/http';
let angular = require('angular');
import { UpgradeAdapter } from '@angular/upgrade';
let adapter = new UpgradeAdapter();
angular.module('myAngular1App', [])
.service('MyAngular1Service', function() {
return {
hello: function() {
console.log('Hello!')
}
}
});
adapter.bootstrap(document.body, ['myAngular1App']);
adapter.upgradeNg1Provider('testService');
@Component({
templateUrl: 'build/app.html'
})
class MyAngular2App {
constructor(@Inject('testService') testService) {
console.log('construct');
testService.hello();
}
}
ionicBootstrap(MyAngular2App, [
HTTP_PROVIDERS
]);
如果没有Angular1 testService
注入,它可以正常工作,但有了它我会看到DI异常 No provider for testService!
:
我在这里缺少什么?