简体   繁体   English

尝试使用混合AngularJS / Angular应用程序时出错

[英]Error trying to do an hybrid AngularJS/Angular app

Im trying to do an hybrid app using AngularJS & Angular(2). 我试图使用AngularJS和Angular做一个混合应用程序(2)。 I already have a big AngularJS app and I just want to use a component from an Angular app. 我已经有一个很大的AngularJS应用程序,我只想使用Angular应用程序中的一个组件。

Using https://angular.io/docs/ts/latest/guide/upgrade.html , I have created two new files 使用https://angular.io/docs/ts/latest/guide/upgrade.html ,我创建了两个新文件

app.module.ts app.module.ts

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

@NgModule({
  imports: [
    BrowserModule,
    UpgradeModule,
  ],
})
export class AppModule {
  ngDoBootstrap() {}
}

and main.ts 和main.ts

import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { UpgradeModule } from '@angular/upgrade/static';
import { AppModule } from './app.module';
import App from './app.js';

platformBrowserDynamic().bootstrapModule(AppModule).then(platformRef => {
  const upgrade = platformRef.injector.get(UpgradeModule) as UpgradeModule;
  upgrade.bootstrap(document.documentElement, [App]);
});

and I have deleted the old bootstrap.js file 我删除了旧的bootstrap.js文件

import angular from 'angular';
import App from './app';

angular.element(function() {
  angular.bootstrap(document, [App], { strictDi: true });
});

The entry of my webpack build is now main.ts . 我的webpack构建的条目现在是main.ts。

When I start my app, I have ana issue : 当我启动我的应用程序时,我有一个问题:

ERROR in ./client/app/main.ts
Module not found: Error: Can't resolve './app.module' in '/home/bsousa/Projects/S6/client/app'
 @ ./client/app/main.ts 5:21-44

Do someone know why ? 有人知道为什么吗?

Here is the tsconfig.json, maybe it can help 这是tsconfig.json,也许它可以帮助

{
  "compilerOptions": {
    "target": "es6",
    "module": "commonjs",
    "allowJs": true,
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": false,
    "allowUnreachableCode": true
  },
  "exclude": [
    "node_modules"
  ]
}

Files structure 文件结构

/
   client
      app
         ...
         app.js
         app.module.ts
         main.ts
   gulpfile.js
   webpack.config.js

Well I don't know why the import did not work but when I set everything in the main.ts file, it works 好吧,我不知道为什么导入不起作用,但是当我在main.ts文件中设置所有内容时,它可以工作

import 'zone.js';
import 'angular';
import App from './app.js';
import { NgModule } from '@angular/core';
import { UpgradeModule } from '@angular/upgrade/static';
import { BrowserModule } from '@angular/platform-browser';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

@NgModule({
  imports: [
    BrowserModule,
    UpgradeModule,
  ],
})
export class AppModule {
  ngDoBootstrap() {
  }
}

platformBrowserDynamic().bootstrapModule(AppModule).then(platformRef => {
  const upgrade = platformRef.injector.get(UpgradeModule) as UpgradeModule;
  upgrade.bootstrap(document.documentElement, [App.name], { strictDi: true });
});

My AngularJS is bootstrapped with Angular. 我的AngularJS是用Angular引导的。

Now I'm trying to import my Angular app into my project as a node package but I think I have to do some improvements with the export. 现在我正在尝试将我的Angular应用程序作为节点包导入我的项目中,但我想我必须对导出做一些改进。

I would like to import the root component, do I have to import the root module as well ? 我想导入根组件,我是否还要导入根模块?

暂无
暂无

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

相关问题 Angular 6 Hybrid应用程序不加载AngularJS组件 - Angular 6 hybrid app does not load AngularJS components 在混合应用程序中找不到AngularJS - AngularJS is not found in Hybrid app 混合应用程序可以在 AngularJS 和 Angular 中使用组件或指令吗? - Can components or directives be used in both AngularJS and Angular for a hybrid app? 在angular / angularjs混合应用程序中使用downgradeModule和downgradeInjectable会导致错误 - Using downgradeModule in conjunction with downgradeInjectable in an angular / angularjs hybrid application results in error 谁能建议如何在 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? 与混合应用程序一起使用时,Angular.js消化进行中错误 - Angularjs digest in progress error while using with hybrid app 在Angular app中使用AngularJS组件时出错:“错误:在设置之前尝试获取AngularJS注入器。” - Error when using AngularJS component inside Angular app: “Error: Trying to get the AngularJS injector before it being set.” 使用 Angular 7 在混合应用程序中加载 Angularjs 包 - Load Angularjs bundle in a hybrid application with Angular 7 $rootScope 在导航时重置 Angular 11 - AngularJS 混合 - $rootScope resets on navigation Angular 11 - AngularJS Hybrid 如何在 Ionic/Angular 混合应用程序中使用cordova inappbrowser 打开链接 - How do I use cordova inappbrowser to open links in Ionic/Angular hybrid app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM