Wednesday 27 November 2013

AngularJS : How to connect AngularJS with MySQL database

                                             How to connect angularjs with MySql database


Now, we are discusses about connect angularjs with backend. It is one of the way to connect database. AngularJS is one of the powerful web application framework. The angularjs is reducing the backend overload.

Understanding the angularjs concept  refer previous tutorials. Easy to understanding server loading data examples:

1.Without AngularJS Web application performance :


First diagram, without using angularjs concept  building web applications diagram. This diagram explains, server workload high and  performance low and response time is very high.


2. With AngularJS web application performance:


Second diagram, building web applications with angularjs - server work load very low and performance very high and response time is very quick processes.

The angularjs is get all data from database and its make JSON(Java Script Object Notation) format.

The connecting angularjs with mysql database.

 First method call to controller site.



sample code :



$scope.addBook = function()
{
http({

method : 'POST',
url: 'index.php?urls',
data: {book_name : $scope.bookName, book_price : $scope.bookPrice},
headers : {'Content-type' : 'application/json'}
}).success(function(data, status, headers, config){

if(data.success)
{
$scope.books.push(data);
 }

}).error(function(data, status, headers, config){

//set error message.

});

}


addBook() is one of the method in view site. The addBook() method call to controller site.

ex:

<button ng-click = "addBook()" >Add book </button>

book_name, book_price  -> books table column names.

$scope.bookName , $scope.bookPrice -> html textbox ngmodel name.

ex:

<input type="text" ng-model="bookName">

<input type="text" ng-model="bookPrice">


Touch with me! Gain more!

19 comments:

  1. Replies
    1. Hi,
      Thank your comments. But front side using same concept.

      Delete
  2. Thanks for posting!
    This is exactly what I needed.

    ReplyDelete
    Replies
    1. Hello, Lacymorrow,

      Thanks for your valuable comment. I hope its useful.

      Delete
  3. Hi, i am new for AngularsJs but i like is, my question is how to connect angularjs with postgres database and use query

    ReplyDelete
    Replies
    1. Hi, Andriamalala Zohajaniaina,

      Thanks for your comments.

      refer this : https://github.com/brianc/node-postgres

      I hope its very useful for you.

      Delete
  4. Hi,

    I have a form written in angular and i want to connect it to a postgresql db so that when i hit the submit button, the data can get stored in the database model. Can you tell me the ways i can try?

    Thank you

    ReplyDelete
    Replies
    1. Hi, Abhishek Reddy Yeruva,

      refer this link

      its very useful.

      https://github.com/brianc/node-postgres/wiki/Example

      Thanks to advance.

      Delete
  5. I want to sale my products online so Can i make dynamic website in angularjs?
    How to connect database through AngularJS.
    Please Tell me in step by step.

    ReplyDelete
    Replies
    1. Hi, Kalu singh rao,

      try this link,

      https://github.com/kenyee/angularjs-cart

      i hope, helpful to you.

      Delete
  6. Hi Kumar,

    Same way how can i connect Mysql database using angularJs via java code???

    ReplyDelete
  7. This comment has been removed by the author.

    ReplyDelete
  8. sir very good site but sir one problem for me angularjs and database connectivity very confusing please sir help me .my email id: (chandresh696@gmail.com)step by step connectivity(angularjs and mysql) .

    ReplyDelete
  9. hai kumar,
    I'm new to angular js I want create one login form with 5 username and password.I tried lot but its not at all work.please give a solution

    ReplyDelete
  10. This comment has been removed by the author.

    ReplyDelete
  11. how to connect angular page with sql using java backend please give me a simple crud operation

    ReplyDelete