Skip to content

joeskeen/ng-integrations

 
 

Repository files navigation

Minimal Starter with Angular on both Server and Browser Platforms

Universal Angular

Angular Universal Starter Universal Angular

Server-Side Rendering for Angular

A minimal Angular starter for Universal JavaScript using TypeScript and Webpack

If you're looking for the Angular Universal repo go to angular/universal

Deploy

Installation

  • npm install

Serve

  • npm start to build your client app and start a web server
  • npm run build to prepare a distributable bundle

Development

  • run npm start and npm run watch in two separate terminals to build your client app, start a web server, and allow file changes to update in realtime

Prod

  • npm run build:prod to compile the ngfactory files and build prod
  • npm run server to start up the server

Universal "Gotchas"

When building Universal components in Angular there are a few things to keep in mind.

  • window, document, navigator, and other browser types - do not exist on the server - so using them, or any library that uses them (jQuery for example) will not work. You do have some options, if you truly need some of this functionality:
    • If you need to use them, consider limiting them to only your main.client and wrapping them situationally with the imported isBrowser / isNode features from Universal. import { isBrowser, isNode } from 'angular2-universal';
    • Another option is using DOM from "@angular/platform-browser"
  • Don't manipulate the nativeElement directly. Use the Renderer. We do this to ensure that in any environment we're able to change our view.
constructor(element: ElementRef, renderer: Renderer) {
  renderer.setElementStyle(element.nativeElement, 'font-size', 'x-large');
}

License

MIT License

About

Examples of integrating Angular with non-Angular libraries

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 97.4%
  • JavaScript 2.5%
  • HTML 0.1%