The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

Winson (32) [Avatar] Offline
I used MongoDB as the persistent storage. I've defined a db service class like this:

export class dbService {
server: mongodb.Server;
client: mongodb.Db;
db: mongodb.Db;
constructor() {

How to initialize the db service class? Inside App class or Dashboard Class?
jeremy.wilken (208) [Avatar] Offline
Anytime you export an object, you just import it where you want to use it. So if you use it in the Dashboard, then you would import it from the file (update the path to be relative to the real location of your class.

import {dbService} from '../services/'

Winson (32) [Avatar] Offline
DBService code:

/// <reference path="../../typings/tsd.d.ts" />
import { StockInterface } from '../services/stocks';
import mongodb = require("mongodb");

export class dbService {
server: mongodb.Server;
client: mongodb.Db;
db: mongodb.Db;

constructor() {
this.server = new mongodb.Server(localhost, 27017, { auto_reconnect: true });
this.client = new mongodb.Db('stock', this.server, { w: 1 }); {});

In dashboard.ts:

import {dbService} from '../services/dbsrv';

export class Dashboard {
stocks: Array<StockInterface>;
symbols: Array<string>;
dbsrv: dbService;

constructor(service: StocksService) {
this.symbols = service.get();

service.load(this.symbols).subscribe(stocks => this.stocks = stocks);

dbsrv = new dbService();

Following errors shown in the browser console:

XHR finished loading: GET "http://localhost:8080/mongodb". system.src.js:1057
Uncaught SyntaxError: Unexpected token <

How can I resolve this error?
jeremy.wilken (208) [Avatar] Offline
When you 'require("mongodb")', TypeScript converts that as if you were trying to use a normal ES6 import. The problem is you don't have the path to mongodb configured, and the server sends back the index.html file for unknown files (to be fixed in the next version of the MEAP).

So I don't know where you got the mongodb code to require, but you'll need to look up how to either 1) configure SystemJS to understand where to find this particular module or 2) manually add the file into your app paths and import it that way.
Winson (32) [Avatar] Offline
If I remark following script section in index.html:

<script src="/lib/"></script>

the web site will fail to start up with error like this:

Uncaught Uncaught SyntaxError: Unexpected token <
Evaluating http://localhost:8080/angular2/angular2

However, I'm not sure which mongodb javascript file to be put into the script section.

I think it is worthwhile to discuss how to integrate Augular2 with MongoDB since
this is quite common configuration
jeremy.wilken (208) [Avatar] Offline
The problem is that you're not loading assets in a way that SystemJS (the module loader) knows how to load. Look at the developer console and you'll see that the content of the file is HTML and not JavaScript, so you can't move files without reconfiguring the SystemJS mapping set in the index.html. Same is true of adding a third party library, it will try to load it from the root of the server, because it doesn't know where to find it.

Try putting the mongodb file into the client/services folder, and then import it using a relative path. Without a full example somewhere, I can't give a specific snippet because it depends on how you've modified the project to this point.

Also take a look at SystemJS as it is used in this demo. We haven't written anything about how to manage it all yet, as Angular has been changing some guidance on the best way to setup a project. We're waiting to see what a more official structure is promoted before we nail down our structure in the book.

As far as Mongo, it really doesn't have any direct impact on Angular 2. We don't have any plans at the moment to write about Mongo or other databases. We will talk about using RESTful APIs, which can be backed by Mongo or other systems.
477578 (8) [Avatar] Offline
The boot option toram makes the system read everything from the system image into RAM during boot. It means that the boot process in slower, but after that the system will be fast. It also means that /cdrom need not be mounted, and if it is a live-only drive, it can be removed or overwritten (for example installed into). But if there is a casper-rw partition or file there and you are running a persistent live session, obviously it is a bad idea to remove the drive.

Otherwise (without toram) the system image is mounted at /cdrom and programs and data are read from there, when needed (which is slower than to read from RAM).
GCLUB ??????