-1

我有一个 Angularjs 应用程序。我必须将它迁移到 Angular。我正在关注角度教程 - https://angular.io/guide/upgrade

我的角度 app.module 看起来像

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

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

    ngDoBootstrap(){
        this.upgrade.bootstrap(document.documentElement, [module.name], {strictDi: true});
    }
}

我在这个文件中导入我的 angularjs 应用程序并手动引导它。

我在引导角度模块 app.module 中添加了一个 main.ts 文件。我的主要 .ts 看起来像

import 'zone.js';
import 'reflect-metadata';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { setAngularLib } from '@angular/upgrade/static';
import * as angular from 'angular';
import { AppModule } from './app.module';

setAngularLib(angular);
platformBrowserDynamic().bootstrapModule(AppModule);

我在 webpack 中添加了 main.ts 作为入口点。

在我的 index.html 中,我删除了 ng-app。我的 index.html 看起来像:

  <script  src="javascripts/main.js">
  <script  src="javascripts/vendor.js">
  <body>
      <main-app></main-pp>

  </body>

是一个 angularJS 组件。main.js 和 vendor.js 是引导程序生成的捆绑文件。

包.json:

{
  "scripts": {
    "dev": "webpack-dev-server --env.env=dev",
    "test": "karma start"
  },
  "dependencies": {
    "angular": "1.6.6",
    "angular-route": "1.6.6",
    "jquery": "^2.2.4",
    "moment": "~2.17.1",
    "bootstrap": "3.3.7",
    "lodash": "4.17.4",
    "@angular/common": "^5.2.5",
    "@angular/compiler": "^5.2.5",
    "@angular/core": "^5.2.5",
    "@angular/forms": "^5.2.5",
    "@angular/platform-browser": "^5.2.5",
    "@angular/platform-browser-dynamic": "^5.2.5",
    "@angular/router": "^5.2.5",
    "@angular/upgrade": "^5.2.5",
    "angular": "1.6.6",
    "angular-route": "1.6.6",
    "bootstrap": "3.3.7",
    "core-js": "^2.5.3",
    "jquery": "^2.2.4",
    "lodash": "4.17.4",
    "moment": "~2.17.1",
    "reflect-metadata": "^0.1.12",
    "rxjs": "^5.5.6",
    "zone.js": "^0.8.20"
  },
  "devDependencies": {
    "@types/angular": "^1.6.39",
    "@types/node": "^8.0.53",
    "angular-mocks": "^1.6.7",
    "autoprefixer": "^7.1.6",
    "css-loader": "^0.28.7",
    "extract-text-webpack-plugin": "^3.0.2",
    "file-loader": "^1.1.5",
    "html-webpack-plugin": "^2.30.1",
    "jasmine-core": "^2.8.0",
    "karma": "^1.7.1",
    "karma-jasmine": "^1.1.0",
    "karma-phantomjs-launcher": "^1.0.4",
    "karma-spec-reporter": "0.0.31",
    "karma-webpack": "^2.0.6",
    "node-sass": "^4.7.2",
    "optimize-css-assets-webpack-plugin": "^3.2.0",
    "phantomjs-prebuilt": "^2.1.16",
    "postcss-loader": "^2.0.9",
    "raw-loader": "^0.5.1",
    "rimraf": "^2.6.2",
    "sass-loader": "^6.0.6",
    "style-loader": "^0.19.0",
    "ts-loader": "^3.1.1",
    "typescript": "2.4.2",
    "webpack": "^3.3.0",
    "webpack-dev-server": "^2.9.5",
    "webpack-merge": "^4.1.1"
  }
}

app.module.ajs 看起来像(跳过导入):

export default angular.module('app', [
mainApp.name,
customers.name,
orders.name
])

但是这个主应用程序没有被渲染。它没有抛出任何错误。如果我添加一些其他静态内容,它会显示该内容但不显示角度分量。

请帮我找出我做错了什么。

4

1 回答 1

0

您是否直接复制/粘贴 index.html?如果是这样,脚本源文件src=""javascripts...应该是单引号的双引号

  <script  src="javascripts/main.js">
  <script  src="javascripts/vendor.js">
  <body>
      <main-app></main-pp>

  </body>

否则,查看您的 .ajs 模块和 package.json 文件可能有助于诊断

于 2018-06-29T22:31:13.043 回答