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!
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!