所以我升级到角度4+只是为了让我可以利用通用包进行服务器端渲染以实现搜索引擎优化目的.我在现有的angular 2+项目中实现了这一点,将其升级为angular 4+并从https://github.com/evertonrobertoauler/cli-universal-demo/commit/a2610286bd3db5d4f4cce4318d7c220c11963eb6完成了所有必要的配置.
我使用ng-bootstrap https://ng-bootstrap.github.io/#/home(v1.0.0- alpha.22)只有一个区别.但是当我使用npm run start-u-dev运行节点服务器时,我在ng-bootstrap中的import关键字出现了这个错误.
app-ui@0.0.0 start-u-dev /Users/giric/Projects/apnaDoctor/webapp/appUI
ts-node src/server.ts
/appUI/node_modules/@ng-bootstrap/ng-bootstrap/accordion/accordion.module.js:1
(function (exports, require, module, __filename, __dirname) { import { NgModule } from '@angular/core';
^^^^^^
SyntaxError: Unexpected token import
at createScript (vm.js:53:10)
at Object.runInThisContext (vm.js:95:10)
at Module._compile (module.js:543:28)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.require (module.js:498:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/appUI/dist/ngfactory/src/app/app.server.module.ngfa
ctory.ts:18:1)
at Module._compile (module.js:571:32)
at Module.m._compile (/appUI/node_modules/ts-node/src/index.ts:406:23)
at Module._extensions..js (module.js:580:10)
at Object.require.extensions.(anonymous function) [as …Run Code Online (Sandbox Code Playgroud) 嗨,我使用的是使用BrowserAnimationsModule的Angular.但在通用服务器端,它给出错误"文档未定义".
因为Universal不支持BrowserAnimationsModule,我需要一种方法让服务器忽略BrowserAnimationsModule并用NoopAnimationsModule替换它.
这就是我现在所拥有的,但它不起作用.任何其他方法也是受欢迎的.
let imports = [
BrowserModule.withServerTransition({appId: 'ang4-seo'}),
FormsModule,
HttpModule,
routes
];
if(isPlatformBrowser(PLATFORM_ID)){
imports.push(BrowserAnimationsModule);
}
@NgModule({
imports: imports,
Run Code Online (Sandbox Code Playgroud)
有什么方法可以解决这个问题吗?