Coder Social home page Coder Social logo

angular2-crud-rest's Introduction

AngularCrudRest

This project was generated with Angular CLI version 1.0.0-rc.2.

Development server

Run ng serve for a dev server. Navigate to http://localhost:4200/. The app will automatically reload if you change any of the source files.

Code scaffolding

Run ng generate component component-name to generate a new component. You can also use ng generate directive/pipe/service/class/module.

Build

Run ng build to build the project. The build artifacts will be stored in the dist/ directory. Use the -prod flag for a production build.

Running unit tests

Run ng test to execute the unit tests via Karma.

Running end-to-end tests

Run ng e2e to execute the end-to-end tests via Protractor. Before running the tests make sure you are serving the app via ng serve.

Further help

To get more help on the Angular CLI use ng help or go check out the Angular CLI README.

angular2-crud-rest's People

Contributors

loiane avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

angular2-crud-rest's Issues

SyntaxError: Use of const in strict mode.

I have downloaded the zip archive from your project, unpacked it and run "ng serve" in the directory. Afterwards I am getting this error:

peter@DESKTOP-UNMGSSF:/mnt/c/Users/peter/Dev/angular2-crud-rest-master$ ng serve

/home/peter/lib/node_modules/@angular/cli/bin/ng:7
const CliConfig = require('../models/config').CliConfig;
^^^^^
SyntaxError: Use of const in strict mode.
at Module._compile (module.js:439:25)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:902:3
peter@DESKTOP-UNMGSSF:/mnt/c/Users/peter/Dev/angular2-crud-rest-master$

Join "DRYSuperFramework" to upgrade your project

Angular2 is growing fast, so probably from your version (2.0.0) and the last stable (^2.4.0) there are many important features/changes so I propose to join my project:

https://github.com/rognoni/DRYSuperFramework

You could move your updated code into the Front-end folder, using:

import { MaterialModule } from '@angular/material';
[...]
  imports: [
    MaterialModule

https://github.com/rognoni/DRYSuperFramework/blob/master/Front-end/src/styles.css

@import '~@angular/material/core/theming/prebuilt/deeppurple-amber.css';

Angular 2 CRUD rest button did not work.

Hello, I'm using angular cli 1.4.3, npm 5.4.2, node 6.11.3.

I create CRUD using angular 2 and rest API. It can read the db but the button for create , read, update and delete did not work. When I click the button it will give this error:

GET http://localhost/Rest%20API/product/read.php60 404 (Not Found)

Failed to load http://localhost/Rest%20API/product/read.php60: No 'Access Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access. The response had HTTP status code 404.

ERROR Response {_body: ProgressEvent, status: 0, ok: false, statusText: "", headers: Headers, …}

Here the code:

app.component,ts

`
import { Component } from '@angular/core';
import { enableProdMode } from '@angular/core';

enableProdMode();

@component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})

export class AppComponent {
// properties for child components
title="Read Products";

product_id;
// properties used to identify what views to show
show_read_products_html=true;
show_create_product_html=false;
show_read_one_product_html=false;
show_update_product_html=false;
show_delete_product_html=false;

// show the 'create product form'
showCreateProduct($event){

	// set title
	this.title=$event.title;

    // hide all html then show only one html
    this.hideAll_Html();
    this.show_create_product_html=true;
}

// show products list
showReadProducts($event){
    // set title
    this.title=$event.title;
 
    // hide all html then show only one html
    this.hideAll_Html();
    this.show_read_products_html=true;
}

// hide all html views
hideAll_Html(){
    this.show_read_products_html=false;
    this.show_read_one_product_html=false;
    this.show_create_product_html=false;
    this.show_update_product_html=false;
    this.show_delete_product_html=false;
}

// show details of a product
showReadOneProduct($event){

    // set title and product ID
    this.title=$event.title;
    this.product_id=$event.product_id;
 
    // hide all html then show only one html
    this.hideAll_Html();
    this.show_read_one_product_html=true;
}

// show the 'update product form'
showUpdateProduct($event){

    // set title and product ID
    this.title=$event.title;
    this.product_id=$event.product_id;
 
    // hide all html then show only one html
    this.hideAll_Html();
    this.show_update_product_html=true;
}

// show 'are you sure?' prompt to confirm deletion of a record
showDeleteProduct($event){
 
    // set title and product ID
    this.title=$event.title;
    this.product_id=$event.product_id;
 
    // hide all html then show only one html
    this.hideAll_Html();
    this.show_delete_product_html=true;
}

}
`

product.php (Rest API)

`<?php
class Product{

// database connection and table name
private $conn;
private $table_name = "products";

// object properties
public $id;
public $name;
public $description;
public $price;
public $category_id;
public $category_name;
public $created;

// constructor with $db as database connection
public function __construct($db){
    $this->conn = $db;
}

// read products
function read()
{

// select all query
$query = "SELECT
            c.name as category_name, p.id, p.name, p.description, p.price, p.category_id, p.created
        FROM
            " . $this->table_name . " p
            LEFT JOIN
                categories c
                    ON p.category_id = c.id
        ORDER BY
            p.created DESC";

// prepare query statement
$stmt = $this->conn->prepare($query);

// execute query
$stmt->execute();

return $stmt;
}

// create product
function create(){

// query to insert record
$query = "INSERT INTO
            " . $this->table_name . "
        SET
            name=:name, price=:price, description=:description, category_id=:category_id, created=:created";

// prepare query
$stmt = $this->conn->prepare($query);

// sanitize
$this->name=htmlspecialchars(strip_tags($this->name));
$this->price=htmlspecialchars(strip_tags($this->price));
$this->description=htmlspecialchars(strip_tags($this->description));
$this->category_id=htmlspecialchars(strip_tags($this->category_id));
$this->created=htmlspecialchars(strip_tags($this->created));

// bind values
$stmt->bindParam(":name", $this->name);
$stmt->bindParam(":price", $this->price);
$stmt->bindParam(":description", $this->description);
$stmt->bindParam(":category_id", $this->category_id);
$stmt->bindParam(":created", $this->created);

// execute query
if($stmt->execute()){
    return true;
}else{
    return false;
}
}

// used when filling up the update product form
function readOne(){

// query to read single record
$query = "SELECT
            c.name as category_name, p.id, p.name, p.description, p.price, p.category_id, p.created
        FROM
            " . $this->table_name . " p
            LEFT JOIN
                categories c
                    ON p.category_id = c.id
        WHERE
            p.id = ?
        LIMIT
            0,1";

// prepare query statement
$stmt = $this->conn->prepare( $query );

// bind id of product to be updated
$stmt->bindParam(1, $this->id);

// execute query
$stmt->execute();

// get retrieved row
$row = $stmt->fetch(PDO::FETCH_ASSOC);

// set values to object properties
$this->name = $row['name'];
$this->price = $row['price'];
$this->description = $row['description'];
$this->category_id = $row['category_id'];
$this->category_name = $row['category_name'];
}

// update the product

function update(){

// update query
$query = "UPDATE
            " . $this->table_name . "
        SET
            name = :name,
            price = :price,
            description = :description,
            category_id = :category_id
        WHERE
            id = :id";

// prepare query statement
$stmt = $this->conn->prepare($query);

// sanitize
$this->name=htmlspecialchars(strip_tags($this->name));
$this->price=htmlspecialchars(strip_tags($this->price));
$this->description=htmlspecialchars(strip_tags($this->description));
$this->category_id=htmlspecialchars(strip_tags($this->category_id));
$this->id=htmlspecialchars(strip_tags($this->id));

// bind new values
$stmt->bindParam(':name', $this->name);
$stmt->bindParam(':price', $this->price);
$stmt->bindParam(':description', $this->description);
$stmt->bindParam(':category_id', $this->category_id);
$stmt->bindParam(':id', $this->id);

// execute the query
if($stmt->execute()){
    return true;
}else{
    return false;
}
}

// delete the product

function delete(){

// delete query
$query = "DELETE FROM " . $this->table_name . " WHERE id = ?";

// prepare query
$stmt = $this->conn->prepare($query);

// sanitize
$this->id=htmlspecialchars(strip_tags($this->id));

// bind id of record to delete
$stmt->bindParam(1, $this->id);

// execute query
if($stmt->execute()){
    return true;
}

return false;
 
}

// search products

function search($keywords){

// select all query
$query = "SELECT
            c.name as category_name, p.id, p.name, p.description, p.price, p.category_id, p.created
        FROM
            " . $this->table_name . " p
            LEFT JOIN
                categories c
                    ON p.category_id = c.id
        WHERE
            p.name LIKE ? OR p.description LIKE ? OR c.name LIKE ?
        ORDER BY
            p.created DESC";

// prepare query statement
$stmt = $this->conn->prepare($query);

// sanitize
$keywords=htmlspecialchars(strip_tags($keywords));
$keywords = "%{$keywords}%";

// bind
$stmt->bindParam(1, $keywords);
$stmt->bindParam(2, $keywords);
$stmt->bindParam(3, $keywords);

// execute query
$stmt->execute();

return $stmt;
}

// read products with pagination

public function readPaging($from_record_num, $records_per_page){

// select query
$query = "SELECT
            c.name as category_name, p.id, p.name, p.description, p.price, p.category_id, p.created
        FROM
            " . $this->table_name . " p
            LEFT JOIN
                categories c
                    ON p.category_id = c.id
        ORDER BY p.created DESC
        LIMIT ?, ?";

// prepare query statement
$stmt = $this->conn->prepare( $query );

// bind variable values
$stmt->bindParam(1, $from_record_num, PDO::PARAM_INT);
$stmt->bindParam(2, $records_per_page, PDO::PARAM_INT);

// execute query
$stmt->execute();

// return values from database
return $stmt;
}

// used for paging products
public function count(){
$query = "SELECT COUNT(*) as total_rows FROM " . $this->table_name . "";

$stmt = $this->conn->prepare( $query );
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);

return $row['total_rows'];
}

}`

Cannot find module 'marked'

Here is the full error message:
Hash: �[1m4e0c4b20b87b517d60cf�[39m�[22m
Time: �[1m12013�[39m�[22mms
chunk {�[1m�[33m0�[39m�[22m} �[1m�[32mpolyfills.bundle.js, polyfills.bundle.js.map�[39m�[22m (polyfills) 232 kB {�[1m�[33m4�[39m�[22m}�[1m�[33m [initial]�[39m�[22m�[1m�[32m [rendered]�[39m�[22m
chunk {�[1m�[33m1�[39m�[22m} �[1m�[32mmain.bundle.js, main.bundle.js.map�[39m�[22m (main) 117 kB {�[1m�[33m3�[39m�[22m}�[1m�[33m [initial]�[39m�[22m�[1m�[32m [rendered]�[39m�[22m
chunk {�[1m�[33m2�[39m�[22m} �[1m�[32mstyles.bundle.js, styles.bundle.js.map�[39m�[22m (styles) 10.5 kB {�[1m�[33m4�[39m�[22m}�[1m�[33m [initial]�[39m�[22m�[1m�[32m [rendered]�[39m�[22m
chunk {�[1m�[33m3�[39m�[22m} �[1m�[32mvendor.bundle.js, vendor.bundle.js.map�[39m�[22m (vendor) 2.92 MB�[1m�[33m [initial]�[39m�[22m�[1m�[32m [rendered]�[39m�[22m
chunk {�[1m�[33m4�[39m�[22m} �[1m�[32minline.bundle.js, inline.bundle.js.map�[39m�[22m (inline) 0 bytes�[1m�[33m [entry]�[39m�[22m�[1m�[32m [rendered]�[39m�[22m

�[1m�[31mERROR in D:/dev/Test/_Angular2code/cd/angular-realworld-example-app-master/src/app/article/markdown.pipe.ts (2,25): Cannot find module 'marked'.�[39m�[22m

�[1m�[31mERROR in D:/dev/Test/_Angular2code/cd/angular-realworld-example-app-master/src/app/article/markdown.pipe.ts (2,25): Cannot find module 'marked'.�[39m�[22m

�[1m�[31mERROR in ./src/app/article/markdown.pipe.ts
Module not found: Error: Can't resolve 'marked' in 'D:\dev\Test_Angular2code\cd\angular-realworld-example-app-master\src\app\article'
@ ./src/app/article/markdown.pipe.ts 8:0-33
@ ./src/app/article/article.module.ts
@ ./src/app/app.module.ts
@ ./src/main.ts
@ multi ./src/main.ts�[39m�[22m

Pesquisa e Paginação em JSON ?

Loiane, estou fazendo todos os projetos do http://loiane.training/, já aprendi muito Obrigado !
Eu estou com uma dúvida neste projeto, como fazer uma pesquisa tipo esta 👍
Tour of Heroes:
http://embed.plnkr.co/71VEirn2WzveVVMuHGp5/

Você tem algum projeto que faça pesquisa em WebService passando um valor como parâmetro e atualize o resultado na gride ? com essa grid paginada ?

tipo isto:
<code>

**buscarPorNome(nome: string): Observable {

	return this.http.get(this.httpUtilLeitor.urlbuscarPorId(this.path + '/' + nome), 
					this.httpUtilLeitor.headers())
                .map(this.httpUtilLeitor.extrairDados)
                .catch(this.httpUtilLeitor.processarErros);
}**

</code>

Obrigado !

Problem with angular2-materialize

I cannot run it with npm start
It is probably related to node_modules that I am using from another project. How properly generate node_modules for this project?
The error is
�[1m�[31mERROR in Error encountered resolving symbol values statically. Could not resolve angular2-materialize relative to D:/dev/Test/_Angular2code/cd/angular2-crud-rest-master/src/app/app.module.ts., resolving symbol AppModule in D:/dev/Test/_Angular2code/cd/angular2-crud-rest-master/src/app/app.module.ts, resolving symbol AppModule in D:/dev/Test/_Angular2code/cd/angular2-crud-rest-master/src/app/app.module.ts�[39m�[22m

�[1m�[31mERROR in multi script-loader!.//jquery/dist/jquery.js script-loader!.//materialize-css/rxjs/add/operator/materialize.js
Module not found: Error: Can't resolve 'D:\dev\Test_Angular2code\cd\angular2-crud-rest-master\node_modules\jquery\dist\jquery.js' in 'D:\dev\Test_Angular2code\cd\angular2-crud-rest-master'
@ multi script-loader!.//jquery/dist/jquery.js script-loader!.//materialize-css/rxjs/add/operator/materialize.js�[39m�[22m

�[1m�[31mERROR in multi script-loader!.//jquery/dist/jquery.js script-loader!.//materialize-css/rxjs/add/operator/materialize.js
Module not found: Error: Can't resolve 'D:\dev\Test_Angular2code\cd\angular2-crud-rest-master\node_modules\materialize-css\rxjs\add\operator\materialize.js' in 'D:\dev\Test_Angular2code\cd\angular2-crud-rest-master'
@ multi script-loader!.//jquery/dist/jquery.js script-loader!.//materialize-css/rxjs/add/operator/materialize.js�[39m�[22m

�[1m�[31mERROR in ./src/main.ts
Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in 'D:\dev\Test_Angular2code\cd\angular2-crud-rest-master\src'
@ ./src/main.ts 4:0-74
@ multi ./src/main.ts�[39m�[22m

�[1m�[31mERROR in ./src/styles.css
Module not found: Error: Can't resolve '../node_modules/materialize-css/dist/css/materialize.css' in 'D:\dev\Test_Angular2code\cd\angular2-crud-rest-master\src'
@ ./src/styles.css 3:10-174
@ multi ./src/styles.css�[39m�[22m

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on all branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because we are using your CI build statuses to figure out when to notify you about breaking changes.

Since we did not receive a CI status on the greenkeeper/initial branch, we assume that you still need to configure it.

If you have already set up a CI for this repository, you might need to check your configuration. Make sure it will run on all new branches. If you don’t want it to run on every branch, you can whitelist branches starting with greenkeeper/.

We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.

Once you have installed CI on this repository, you’ll need to re-trigger Greenkeeper’s initial Pull Request. To do this, please delete the greenkeeper/initial branch in this repository, and then remove and re-add this repository to the Greenkeeper integration’s white list on Github. You'll find this list on your repo or organiszation’s settings page, under Installed GitHub Apps.

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.