victormejia / angular-node-contact-manager Goto Github PK
View Code? Open in Web Editor NEWHome Page: https://www.linkedin.com/learning/angular-api-communication-and-authentication
Home Page: https://www.linkedin.com/learning/angular-api-communication-and-authentication
Hello. When I do "npm run sample", I get this error after console logged "connected to mongodb..."
/Users/.../node_modules/mongodb/lib/mongo_client.js:421
throw err
^
TypeError: Cannot read property 'collection' of null
Hi Victor,
thank you so much for your lessons on Angular and JWT!
In your last video you use a Guard for the "contact" and "add" route, but for the "login" route you only use the router.redirect functions in the ngOnInit lifecycle hook.
Why do you use the router redirect at login, but not at the contact route? Or - vice versa - why do you not use a guard for the login route?
Thanks in advanced!
Florian
I have to use the version used in the tutorial, but that is not ideal if I am in learning mongodb for now.
Any input helps.
DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect.
typeorm/mongo-typescript-example#1
`require('dotenv').config();
const users = require('./users');
const contacts = require('./contacts');
const MongoClient = require('mongodb').MongoClient;
const bcrypt = require('bcrypt');
function seedCollection(collectionName, initialRecords) {
MongoClient.connect(process.env.DB_CONN, (err, db) => {
console.log('connected to mongodb...');
const collection = db.collection(collectionName);
collection.remove();
initialRecords.forEach((item) => {
if (item.password) {
item.password = bcrypt.hashSync(item.password, 10);
}
});
collection.insertMany(initialRecords, (err, result) => {
console.log(`${result.insertedCount} records inserted.`);
console.log('closing connection...');
db.close();
console.log('done.');
});
});
}
seedCollection('users', users);
seedCollection('contacts', contacts);
`
hi
how to create api service with angular 5?
use: @angular/common/http
please help me and update code
import { Injectable } from '@angular/core';
import { Http, Headers, Request, RequestOptions, RequestMethod, Response } from '@angular/http';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch';
import 'rxjs/add/observable/throw';
import { Observable } from 'rxjs/Observable';
import { environment } from '../../environments/environment';
import { AuthService } from './auth.service';
@Injectable()
export class ApiService {
private baseUrl = environment.apiUrl;
constructor(private http: Http, private auth: AuthService) { }
get(url: string) {
return this.request(url, RequestMethod.Get);
}
post(url: string, body: Object) {
return this.request(url, RequestMethod.Post, body);
}
put(url: string, body: Object) {
return this.request(url, RequestMethod.Put, body);
}
delete(url: string) {
return this.request(url, RequestMethod.Delete);
}
request(url: string, method: RequestMethod, body?: Object) {
const headers = new Headers();
headers.append('Content-Type', 'application/json');
headers.append('Authorization', `Bearer ${this.auth.getToken()}`);
const requestOptions = new RequestOptions({
url: `${this.baseUrl}/${url}`,
method: method,
headers: headers
});
if (body) {
requestOptions.body = body;
}
const request = new Request(requestOptions);
return this.http.request(request)
.map((res: Response) => res.json())
.catch((res: Response) => this.onRequestError(res));
}
onRequestError(res: Response) {
const statusCode = res.status;
const body = res.json();
const error = {
statusCode: statusCode,
error: body.error
};
console.log(error);
return Observable.throw(error);
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.