Coder Social home page Coder Social logo

angular-node-contact-manager's People

Contributors

victormejia avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

angular-node-contact-manager's Issues

how to create api service with angular 5?

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);
  }

}

01_02 before end Latest MongoDb version getting error.

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

https://www.google.com/search?ei=3RfiW-edFKvjjwSGm7aABg&q=mongodb+To+use+the+new+parser%2C+pass+option+%7B+useNewUrlParser%3A+true+%7D+to+MongoClient.connect.&oq=mongodb+To+use+the+new+parser%2C+pass+option+%7B+useNewUrlParser%3A+true+%7D+to+MongoClient.connect.&gs_l=psy-ab.3...1638.3410..3738...1.0..0.158.1242.0j9......0....1..gws-wiz.......0i7i30.RVO3V27zwsE

`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);
`

05_05 When use Guard and when use Redirect

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.