我有一个使用RangalJS 1.69的现有RaSoR/MVC应用程序。为了与合作伙伴团队共享组件,我们必须创建一个临时的Angular5应用程序,以便通过NPM使用一些共享组件。在我们的Angular5应用程序中,我们会导入共享组件,然后将它们降级,这样我们就可以在我们的1.6.9应用程序中使用它们,而且这一操作非常完美。我们遵循了概述的步骤
here
.需要注意的一点是,ngsixmodule1定义了我们在其入口组件中使用的组件,这就是为什么它没有在app.module.ts中明确定义(这适用于angular 5)
然而,我们的合作团队最近提出了升级角6,我们正试图做同样的事情。但是在执行了所有必要的升级命令之后,ui不会呈现这些共享元素。我们的
ng build --prod
可以,但当我们尝试呈现页面时,页面将加载减去这些共享组件的内容。
正如我上面所说,这在角度5中工作得很好,一旦我升级到角度6,它就会停止工作。任何洞察都将不胜感激:)
FIY在控制台窗口中没有错误,并且呈现了标记,但是没有显示出来。
应用模块.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
)
第.cshtml页
<script type="text/javascript">
var app = angular.module("MyApp", ['module-name', 'ngRoute']);
app.controller("controllerName", function ($scope, $rootScope, $sce, $http, xpost) {
});
</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>
包.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"
}
}