I'm brand new to Angular and just getting started on getting my head wrapped around how it works. Please, Internet, be gentle...
I've completed the Angular2 5 min Quickstart through Tour of Heroes and have that working without an issue. Now I'm trying get connectivity to my local MS SQL server as I have a SQL-based project coming where Angular2 is the required platform. I've been banging my head against the wall for days on getting Sequelize to work and could really use some help.
What I've done so far based on different things I've read:
- Used npm to install sequelize and verified that sequelize and the dependencies of lodash, bluebird and validator all exist under node_modules
- Downloaded bluebird.d.ts, lodash.d.ts, sequelize.d.ts and validator.d.ts from the DefinitelyTyped project on GitHub and put them in my typings folder
- In tsConfig.json, I changed the compilerOptions --> target from es5 to es6
- Created a simple db.component.ts file (see below)
- Updated app.component.ts to import the db.component and added a route to it
At this point the simple page comes up, but I am unable to figure out how to get Sequelize working.
Script errors I'm seeing (based on using Visual Studio Code as my editor):
- When I open sequelize.d.ts, there is an error on the line 'declare module "sequelize" {' stating that "Ambient modules cannot be nested other modules"
- When I open lodash.d.ts, there are errors on lines 239 and 240 (the underscores) that states "Duplicate Identifier '_'"
I've tried a number of different approaches (guesses) on how to get sequelize to connect to my database and just cannot get anything to work. I understand that I need either (both?) an import and/or a require in the db.component.ts file, but only end up with errors either in the IDE as bad syntax or in the browser (Chrome).
I do understand that in the long run, my route/config/etc that I'm testing with here is not going to be the "right" way to do it, but I just need to get past the basic proof-of-concept that I can do something with the database before I re-engineer it (e.g. - can I connect to the database and query a table)
app.component.ts
import { Component } from 'angular2/core';
import { RouteConfig, ROUTER_DIRECTIVES, ROUTER_PROVIDERS } from 'angular2/router';
import { DashboardComponent } from './dashboard.component';
import { HeroService } from './hero.service';
import { HeroesComponent } from './heroes.component';
import { HeroDetailComponent } from './hero-detail.component';
import { dbComponent } from './db.component';
@Component({
selector: 'my-app',
template: `
<h1>{{title}}</h1>
<nav>
<a [routerLink]="['Dashboard']">Dashboard</a>
<a [routerLink]="['Heroes']">Heroes</a>
</nav>
<router-outlet></router-outlet>
`,
styleUrls: ['app/app.component.css']
directives: [ROUTER_DIRECTIVES],
providers: [
ROUTER_PROVIDERS,
HeroService
]
})
@RouteConfig([
{
path: '/dashboard',
name: 'Dashboard',
component: DashboardComponent,
useAsDefault: true
},
{
path: '/heroes',
name: 'Heroes',
component: HeroesComponent
},
{
path: '/detail/:id',
name: 'HeroDetail',
component: HeroDetailComponent
},
{
path: '/sql',
name: 'SqlTest',
component: dbComponent
}
])
export class AppComponent {
title = 'Sample App';
}
db.component.ts
/// <reference path="../typings/sequelize.d.ts" />
import { Component, OnInit } from 'angular2/core';
import Sequelize = require('sequelize'); <-- I dont know if this is doing anything
//- This just errors out with require not being found (tds@latest installed)
//var Sequelize = require("sequelize");
//- I know this goes somewhere, but I have no idea where
//var sql = new Sequelize('dbName', 'uName', 'pw', {
// host: "127.0.0.1",
// dialect: 'mssql',
// port: 1433 <-- SqlExpress
//});
@Component({
selector: 'my-sql',
template:`
<h1>SQL Test</h1>
`
})
export class dbComponent implements OnInit {
constructor(
) { }
auth() {
console.log('auth');
//sql.authenticate().then(function(errors) { console.log(errors) });
}
ngOnInit() {
console.log('onInit');
this.auth();
}
}
My console.log message are coming up so I believe that I have the core functionality basically working, but I'm at a loss on what I need to do to get Sequelize functional.
There's a piece of the puzzle that I'm missing and I'm at my wits end on this. Thanks in advance for any direction...