explore-services/portal-2
argiro.kokogiannaki 136995ed44 In pubs/data search page: Search also for DOI when keyword is only one word| In pubs/data Advanced search page: new field PID
git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-portal/trunk@44739 d315682c-612b-4755-9ff5-7f18f6832af3
2016-11-30 11:54:45 +00:00
..
src In pubs/data search page: Search also for DOI when keyword is only one word| In pubs/data Advanced search page: new field PID 2016-11-30 11:54:45 +00:00
.editorconfig commiting a more complete version of the project 2016-09-22 13:54:26 +00:00
.gitignore Update and refactor to the latest version of angular universal starter repo -> 2016-11-22 2016-11-22 13:36:12 +00:00
README.md Update and refactor to the latest version of angular universal starter repo -> 2016-11-22 2016-11-22 13:36:12 +00:00
app.json commiting a more complete version of the project 2016-09-22 13:54:26 +00:00
empty.js Update and refactor to the latest version of angular universal starter repo -> 2016-11-22 2016-11-22 13:36:12 +00:00
nodemon.json commiting a more complete version of the project 2016-09-22 13:54:26 +00:00
npm-shrinkwrap.json.stable Fix server rendering issue by updating Zone.js from 0.6.21 to 0.6.23 2016-09-29 13:22:54 +00:00
package.json update angular-universal-starter project, use API resources for advanced Search, put totalResults in searchUtils.class, use new API version for publications simple search 2016-11-29 10:42:17 +00:00
package.json_ Update and refactor to the latest version of angular universal starter repo -> 2016-11-22 2016-11-22 13:36:12 +00:00
tsconfig.aot.json Update and refactor to the latest version of angular universal starter repo -> 2016-11-22 2016-11-22 13:36:12 +00:00
tsconfig.json Update and refactor to the latest version of angular universal starter repo -> 2016-11-22 2016-11-22 13:36:12 +00:00
webpack.config.ts update angular-universal-starter project, use API resources for advanced Search, put totalResults in searchUtils.class, use new API version for publications simple search 2016-11-29 10:42:17 +00:00
webpack.prod.config.ts update angular-universal-starter project, use API resources for advanced Search, put totalResults in searchUtils.class, use new API version for publications simple search 2016-11-29 10:42:17 +00:00

README.md

<img src="https://cloud.githubusercontent.com/assets/1016365/10639063/138338bc-7806-11e5-8057-d34c75f3cafc.png" alt="Universal Angular 2" height="320"/>

Angular 2 Universal Starter Universal Angular 2

Server-Side Rendering for Angular 2

A minimal Angular 2 starter for Universal JavaScript using TypeScript 2 and Webpack 2

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

Deploy

Universal "Gotchas"

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

  • To use templateUrl or styleUrls you must use angular2-template-loader in your TS loaders.
    • This is already setup within this starter repo. Look at the webpack.config file here for details & implementation.
  • 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');
}
  • The application runs XHR requests on the server & once again on the Client-side (when the application bootstraps)
    • Use a UniversalCache instead of regular Http, to save certain requests so they aren't re-ran again on the Client.
  • Know the difference between attributes and properties in relation to the DOM.
  • Keep your directives stateless as much as possible. For stateful directives, you may need to provide an attribute that reflects the corresponding property with an initial string value such as url in img tag. For our native element the src attribute is reflected as the src property of the element type HTMLImageElement.

Upcoming Universal features

  • SeoServices
  • Universal fixes for Angular Core 2.1.1

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

Watch files

  • npm run watch to build your client app and start a web server

AoT and Prod

  • npm run build:prod:ngc to compile the ngfactory files and build prod

Edge case of server compatibility with Promise polyfills

If you have node modules with promise polyfill dependency on server - there is chance to get the following exception:

Error: Zone.js has detected that ZoneAwarePromise `(window|global).Promise` has been overwritten.

It occurs because Zone.js Promise implementation is not detected as Promise by some polyfills (e.g. es6-promise before 4.x).

To sort it out, you need such polyfills initialized before zone.js. Zone.js is initialized in 'angular2-universal-polyfills' import of server.ts. So import problematic modules before this line.

Documentation

Design Doc

Videos

Angular 2 Universal Patterns - ng-conf, May 2016
Angular 2 Universal Patterns

Angular Universal Source Code - ReadTheSource, January 2016
Angular Universal Source Code

Full Stack Angular 2 - AngularConnect, Oct 2015
Full Stack Angular 2

Angular 2 Server Rendering - Angular U, July 2015
Angular 2 Server Rendering

preboot.js

Control server-rendered page and transfer state before client-side web app loads to the client-side-app.

License

MIT License