降级的Angular 6组件(至AngularJS 1.6.9)无法呈现UI

时间:2018-10-17 01:55:17

标签: javascript angularjs angular angular6 downgrade

我有一个现有的Razor / MVC应用程序,该应用程序也使用AngularJS 1.6.9。为了与合作伙伴团队共享组件,我们必须创建一个临时的Angular 5应用程序,以便通过NPM使用某些共享组件。在我们的Angular 5应用程序中,我们将导入共享组件,然后降级它们,以便我们可以在1.6.9应用程序中使用它们,并且可以完美地工作。我们遵循了here概述的步骤。需要注意的一件事是NgSixModule1定义了我们在其入口组件中使用的组件,这就是为什么未在app.module.ts中明确定义它的原因(这适用于Angular 5)

但是,我们的合作伙伴团队最近对Angular 6进行了升级,我们正在尝试这样做。但是在执行所有必要的升级命令后,UI不会呈现那些共享元素。我们的ng build --prod可以工作,但是当我们尝试渲染页面时,该页面将加载减去这些共享组件。

如上所述,这在Angular 5中非常有效,一旦我升级到Angular 6,它就会停止工作。任何见识将不胜感激:)

仅供参考,控制台窗口中没有错误,并且呈现了标记,但未显示任何内容。

app.module.ts

@NgModule({
  imports: [
    BrowserModule,
    UpgradeModule,
    HttpClientModule,
    NgSixModule1
  ],
  declarations: [],
  entryComponents: [],
  providers: []
})
export class AppModule {
  constructor(private upgrade: UpgradeModule) { }
  ngDoBootstrap() {
    this.upgrade.bootstrap(document.getElementById("my-app-container"), ["MyApp"]);
  }
}

declare var angular: any;
angular
  .module("module-name", [])
  .directive(
    "componentOne",
    downgradeComponent({ component: ComponentOneComponent }) as angular.IDirectiveFactory
  )
  .directive(
    "componentTwo",
    downgradeComponent({ component: ComponentTwoComponent }) as angular.IDirectiveFactory
  )

page.cshtml

<script type="text/javascript">
    var app = angular.module("MyApp", ['module-name', 'ngRoute']);

    app.controller("controllerName", function ($scope, $rootScope, $sce, $http, xpost) {
        // Controller information
    });
</script>

<div ng-controller="controllerName" id="my-app-container">
    <shared-component-one></shared-component-one>
    <shared-component-two>
        <REST OF THE HTML>
    </shared-component-two>
</div>

package.json

{
  "name": "module-name",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build --prod",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "6.1.10",
    "@angular/common": "6.1.10",
    "@angular/compiler": "6.1.10",
    "@angular/core": "6.1.10",
    "@angular/forms": "6.1.10",
    "@angular/http": "6.1.10",
    "@angular/platform-browser": "6.1.10",
    "@angular/platform-browser-dynamic": "6.1.10",
    "@angular/router": "6.1.10",
    "@angular/upgrade": "6.1.10",
    "@shared/component": "^6.5.5",
    "angular": "1.6.9",
    "core-js": "^2.4.1",
    "moment": "^2.22.2",
    "rxjs": "^6.3.3",
    "zone.js": "~0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.8.0",
    "@angular/cli": "^6.2.5",
    "@angular/compiler-cli": "6.1.10",
    "@angular/language-service": "6.1.10",
    "@types/angular": "^1.6.43",
    "@types/jasmine": "~2.8.3",
    "@types/jasminewd2": "~2.0.2",
    "@types/node": "~6.0.60",
    "codelyzer": "^4.0.1",
    "jasmine-core": "~2.8.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~2.0.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "^1.2.1",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.1.2",
    "ts-node": "~4.1.0",
    "tslint": "~5.9.1",
    "typescript": "2.9.2"
  }
}

1 个答案:

答案 0 :(得分:0)

我能够弄清楚。问题是从迁移到Angular 6的构建步骤产生了不同的输出文件。以前,我们使用的是inline*.js,但升级后,它移到了runtime*.js。我必须更改页面上的某些逻辑以包含runtime版本而不是inline,然后它才起作用。