В настоящее время я перемещаю кодовую базу OPPIA https://github.com/oppia/oppia из AngularJS (1.x) в Angular (2+). Я перенес службу UtilsService.ts (https://github.com/oppia/oppia/blob/develop/core/templates/dev/head/services/UtilsService.ts) на следующее:
import { Injectable } from '@angular/core';
import { downgradeInjectable } from '@angular/upgrade/static';
@Injectable({
providedIn: 'root'
})
export class UtilsService {
isEmpty(obj: any): boolean {
for (var property in obj) {
if (obj.hasOwnProperty(property)) {
return false;
}
}
return true;
}
isString(input: any): boolean {
return (typeof input === 'string' || input instanceof String);
}
}
angular.module('oppia').factory(
'UtilsService',
downgradeInjectable(UtilsService));
Эта служба используется во многих других службах и директивах. Я получаю эту ошибку при запуске приложениясейчас.
StaticInjectorError(ExplorationEditorPageModule)[String]:
StaticInjectorError(Platform: core)[String]:
NullInjectorError: No provider for String!
StaticInjectorError(Platform: core)[String]:
NullInjectorError: No provider for String!
at NullInjector.push../node_modules/@angular/core/fesm5/core.js.NullInjector.get (webpack:///node_modules/@angular/core/fesm5/core.js:725:0)
at resolveToken (webpack:///node_modules/@angular/core/fesm5/core.js:11917:0)
at tryResolveToken (webpack:///node_modules/@angular/core/fesm5/core.js:11861:0)
at StaticInjector.push../node_modules/@angular/core/fesm5/core.js.StaticInjector.get (webpack:///node_modules/@angular/core/fesm5/core.js:11763:0)
at resolveToken (webpack:///node_modules/@angular/core/fesm5/core.js:11917:0)
at tryResolveToken (webpack:///node_modules/@angular/core/fesm5/core.js:11861:0)
at StaticInjector.push../node_modules/@angular/core/fesm5/core.js.StaticInjector.get (webpack:///node_modules/@angular/core/fesm5/core.js:11763:0)
at resolveNgModuleDep (webpack:///node_modules/@angular/core/fesm5/core.js:20233:0)
at NgModuleRef_.push../node_modules/@angular/core/fesm5/core.js.NgModuleRef_.get (webpack:///node_modules/@angular/core/fesm5/core.js:20904:0)
at injectInjectorOnly (webpack:///node_modules/@angular/core/fesm5/core.js:628:0)
at URL: http://localhost:8181/create/hCByec28SLfx#/gui/Introduction
Вот так выглядит модуль ExplorationEditorPageModule - https://github.com/oppia/oppia/blob/develop/core/templates/dev/head/pages/exploration-editor-page/exploration-editor-page.module.ts.
Я застрял здесь и не могу продолжить.