gpt4 book ai didi

angularjs - 在 apache tomcat 上运行 angularjs 2 应用程序

转载 作者:行者123 更新时间:2023-11-28 22:01:42 24 4
gpt4 key购买 nike

我有一个在 apache tomcat 上运行的 angularjs 应用程序。我尝试使用升级适配器同时使用 angular1 和 angular2,但是一旦我删除了 ng-app 指令,我的应用程序就会停止工作,尽管已经使用升级适配器来引导应用程序以及迁移指南中提到的后续步骤。我不是在控制台上出现任何错误。它只是空白。

有什么方法可以在 tomcat 上完成吗?到目前为止,我只看到在 npm lite-server 上运行的示例 angular2 应用程序。

index.html

<!-- inject:system:js --><script src="/app/dist/system.src.js"></script><!-- endinject -->
<!-- inject:router:js --><script src="/app/dist/router.dev.min.js"></script><!-- endinject -->
<!-- inject:systemjs:js --><script src="/app/dist/systemjs.config.js"></script><!-- endinject -->

<base href="/index.html">

<my-app></my-app>
</body>
</html>

系统js.config.js

     (function(global) {
// map tells the System loader where to look for things
var map = {
'app': 'app', // 'dist',
'@angular': 'node_modules/@angular',
'angular2-in-memory-web-api': 'node_modules/angular2-in-memory-web-api',
'rxjs': 'node_modules/rxjs'
};
// packages tells the System loader how to load when no filename and/or no extension
var packages = {
'app': { main: 'main.js', defaultExtension: 'js' },
'rxjs': { defaultExtension: 'js' },
'angular2-in-memory-web-api': { main: 'index.js', defaultExtension: 'js' },
};
var ngPackageNames = [
'common',
'compiler',
'core',
'http',
'platform-browser',
'platform-browser-dynamic',
'router',
'router-deprecated',
'upgrade',
];
// Individual files (~300 requests):
function packIndex(pkgName) {
packages['@angular/'+pkgName] = { main: 'index.js', defaultExtension: 'js' };
}
// Bundled (~40 requests):
function packUmd(pkgName) {
packages['@angular/'+pkgName] = { main: pkgName + '.umd.js', defaultExtension: 'js' };
};
// Most environments should use UMD; some (Karma) need the individual index files
var setPackageConfig = System.packageWithIndex ? packIndex : packUmd;
// Add package entries for angular packages
ngPackageNames.forEach(setPackageConfig);
var config = {
map: map,
packages: packages
}
System.config(config);
})(this);
System.import('/app/main.js').then(null, console.error.bind(console));

主要.ts

 import { upgradeAdapter } from './upgrade-adapter';
upgradeAdapter.bootstrap(document.body, ['utdApp']);

升级适配器.ts

import { UpgradeAdapter} from '@angular/upgrade';
export const upgradeAdapter = new UpgradeAdapter();

最佳答案

Is there any way this can be done on tomcat?

当然。 Tomcat、Express、Apache、最简单的节点服务器 - 无论您喜欢什么网络服务器,都没关系。

as soon as i remove the ng-app directive my application stops working... I am not getting any errors on the console either.

听起来您只需要正确引导 Angular 应用程序。检查angular.bootstrap如果您需要引导 Angular 1 应用 angular.bootstrap(appRootNode, ['appModuleName']]); 直到您迁移到 Angular 2 引导方法。

关于angularjs - 在 apache tomcat 上运行 angularjs 2 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38148461/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com