简体   繁体   English

Angular 6 Hybrid应用程序不加载AngularJS组件

[英]Angular 6 hybrid app does not load AngularJS components

I aim to upgrade a large AngularJS version 1.7.3 to a hybrid app using Angular 6. I finished the preparation phase where I had to convert all my controllers/directives into an AngularJS component. 我打算使用Angular 6将大型AngularJS 1.7.3版升级到混合应用程序。我完成了准备阶段,在该阶段中,我必须将所有控制器/指令都转换为AngularJS组件。 I have created a new Angular 6 project skeleton with the command line: 我用命令行创建了一个新的Angular 6项目框架:

 ng new hybrid-app

I copy-pasted the AngularJS legacy code inside the Angular 6 app in src/ng1 folder. 我将Angular 6应用程序中的AngularJS旧代码复制粘贴到src / ng1文件夹中。

This is how my app.module.ts look like in order to bootstrap the AngularJS 1.x app from Angular 6: 这是我的app.module.ts的外观,以便从Angular 6引导AngularJS 1.x应用程序:

 import {BrowserModule} from '@angular/platform-browser';
 import {NgModule} from '@angular/core';
 import {UpgradeModule} from '@angular/upgrade/static';
 import {AppComponent} from './app.component';

 @NgModule({
   declarations: [
    AppComponent
   ],
 imports: [
  BrowserModule,
  UpgradeModule
 ],
 providers: [],
  // bootstrap: [AppComponent] // No Bootstrap-Component
})
 export class AppModule {
   constructor(private upgrade: UpgradeModule) {
 }

 ngDoBootstrap() {
  this.upgrade.bootstrap(document.body, ['myAngularJsModule'], {strictDi: 
   true});
 }
}

When I do ng serve, there is no error and I can see the Angular 6 app redirecting to the default AngularJS routing which is /login. 当我提供服务时,没有错误,我可以看到Angular 6应用程序重定向到默认的AngularJS路由/ login。 This is my AngularJS route file: 这是我的AngularJS路由文件:

 angular.module('myAngularJsModule').config(["$locationProvider", function ($locationProvider) {
    $locationProvider.html5Mode(false);
}])
.config(
    ['$stateProvider', '$urlRouterProvider', '$locationProvider',
        function ($stateProvider, $urlRouterProvider) {

            /**
             * Default route.
             */
            $urlRouterProvider.otherwise('/login');

            $stateProvider
                .state('login', {
                    url: '/login',
                    params: {message: null},
                    component: 'loginComponent',
                    template: '<login-component></login-component>'
                });

As you can see I have a default route to /login and the Angular 6 app knows how to get there. 如您所见,我有到/ login的默认路由,Angular 6应用知道如何到达。 The issue that I have now is: 我现在遇到的问题是:

There is no error in the console but I have a blank page, it seems like component from AngularJS is not loaded properly and therefore does not show anything on the browser. 控制台中没有错误,但是我有一个空白页,看来AngularJS的组件未正确加载,因此在浏览器上未显示任何内容。 I tried to replace the template by a simple: 我尝试用简单的方法替换模板:

 template: '<h1>Hello World!<h1>'

And it will show up properly. 并且它将正确显示。 Anyone knows why my AngularJS component is not loaded by Angular 6, is it something to do with the UIRouter? 任何人都知道为什么Angular 6不会加载我的AngularJS组件,这与UIRouter有关吗?

The error that I have now is: 我现在遇到的错误是:

 Error: StaticInjectorError(AppModule)[UpgradeModule -> Injector]: 
 StaticInjectorError(Platform: core)[UpgradeModule -> Injector]: 
NullInjectorError: No provider for Injector!
at NullInjector.push../node_modules/@angular/core/fesm5/core.js.NullInjector.get (core.js:1062)
at resolveToken (core.js:1300)
at tryResolveToken (core.js:1244)
at StaticInjector.push../node_modules/@angular/core/fesm5/core.js.StaticInjector.get (core.js:1141)
at resolveToken (core.js:1300)
at tryResolveToken (core.js:1244)
at StaticInjector.push../node_modules/@angular/core/fesm5/core.js.StaticInjector.get (core.js:1141)
at resolveNgModuleDep (core.js:8376)
at _createClass (core.js:8423)
at _createProviderInstance (core.js:8393)

I may need to have a look at this: https://github.com/ui-router/angular-hybrid 我可能需要看看这个: https : //github.com/ui-router/angular-hybrid

I will delete my old angular-ui-router and replace it by this one. 我将删除我的旧的angular-ui-router,并用这个替换。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 混合应用程序可以在 AngularJS 和 Angular 中使用组件或指令吗? - Can components or directives be used in both AngularJS and Angular for a hybrid app? 使用 Angular 7 在混合应用程序中加载 Angularjs 包 - Load Angularjs bundle in a hybrid application with Angular 7 尝试使用混合AngularJS / Angular应用程序时出错 - Error trying to do an hybrid AngularJS/Angular app 在混合应用程序中找不到AngularJS - AngularJS is not found in Hybrid app $rootScope 在导航时重置 Angular 11 - AngularJS 混合 - $rootScope resets on navigation Angular 11 - AngularJS Hybrid Angular 2+是加载整个模块还是只加载导出的组件? - Does Angular 2+ load whole module or just exported components? angular 路由器更改 url 但不加载组件/页面 - angular router changes url but does not load the components / pages 谁能建议如何在 AngularJS/Angular 混合应用程序中进一步调试这个 HttpClient 注入错误(没有 http_HttpClient 的提供者)? - Can anyone advise how to further debug this HttpClient injection error (No provider for http_HttpClient) in an AngularJS/Angular hybrid app? 单元测试混合角度/反应应用程序 - Unit testing a hybrid angular/react app 自定义过滤器在 Angular Hybrid 应用程序中不起作用 - Custom filter not working in Angular Hybrid app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM