Skip to main content

Crud Angular JS

<!DOCTYPE HTML>
<html ng-app="myapp">
<head>
<title>Angular Js Crud</title>
<script type="text/javascript" src="angular.min.js"></script>
</head>
<body ng-controller="productController">
<table cellpadding="2" cellspacing='2' border="1px">
<tr>
<th>Id </th>
<th>Name </th>
<th>Price </th>
<th>Quantity </th>
<th>option </th>
</tr>
<tr ng-repeat="product in listproduct">
<td>{{product.id}}</td>
<td>{{product.name}}</td>
<td>{{product.price}}</td>
<td>{{product.quantity}}</td>
<td>
<a href="#" ng-click="del(product.id)">Delete</a> |
<a href="#" ng-click="selectEdit(product.id)">Edit</a>
</td>
</tr>

</table>
<h3>product Information </h3>
<table cellpadding='2' cellspacing='2'>
<tr>
<td>Id</td>
<td><input type='text' ng-model='id'></td>
</tr>
<tr>
<td>Name</td>
<td><input type="text" ng-model="name"></td>
</tr>
<tr>
<td>Price</td>
<td><input type="text" ng-model='price'></td>
</tr>
<tr>
<td>Quantity</td>
<td><input type='text' ng-model='quantity'></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>
<input type='button' value="Add" ng-click="add()">
<input type='button' value="Save" ng-click="edit()">
</td>
</tr>



</table>
<script>
var myapp = angular.module('myapp', []);
myapp.controller('productController',function($scope){
$scope.listproduct = [
{id: 'p01',name:'Mobile',price:10000, quantity:20},
{id: 'p02',name:'Fridge',price:50000, quantity:20},
{id: 'p03',name:'TV',price:45000, quantity:20},
{id: 'p04',name:'Desktop',price:12500, quantity:20},
{id: 'p05',name:'Air Contion',price:75000, quantity:20},
];

$scope.add = function(){
$scope.listproduct.push({
id:$scope.id, name:$scope.name, price:$scope.price, quantity:$scope.quantity
});
$scope.id = '';
$scope.name = '';
$scope.price = '';
$scope.quantity = '';
};

$scope.edit = function(){
var index = getSelectIndex($scope.id);
$scope.listproduct[index].name = $scope.name;
$scope.listproduct[index].price = $scope.price;
$scope.listproduct[index].quantity = $scope.quantity;

};


$scope.selectEdit = function(id){
var index = getSelectIndex(id);
var product = $scope.listproduct[index];
$scope.id = product.id;
$scope.name = product.name;
$scope.price = product.price;
$scope.quantity = product.quantity;
};

$scope.del = function(id){
var result = confirm('Are you sure?');
var index =  getSelectIndex(id);
$scope.listproduct.splice(index, 1);

};
function getSelectIndex(id){
for(var i=0;i<$scope.listproduct.length; i++)
if($scope.listproduct[i].id==id)
return i;
return -1;

}
});

</script>
</body>


























</html>

Comments

Popular posts from this blog

IDB HTML MCQ

Questions: 1. A webpage displays a picture. What tag was used to display that picture? a. picture b. image c. img d. src 2. <b> tag makes the enclosed text bold. What is other tag to make text bold? a. <strong> b. <dar> c. <black> d. <emp> 3. Tags and test that are not directly displayed on the page are written in _____ section. a. <html> b. <head> c. <title> d. <body> 4. Which tag inserts a line horizontally on your web page? a. <hr> b. <line> c. <line direction=”horizontal”> d. <tr> 5. What should be the first tag in any HTML document? a. <head> b. <title> c. <html> d. <document> 6. Which tag allows you to add a row in a table? a. <td> and </td> b. <cr> and </cr> c. <th> and </th> d. <tr> and </tr> 7. How can you make a bulleted list? a. <list> b. <nl> c. <ul> d. <ol> 8. Ho

Database Connection with PHP PDO MYSQL

PDO Connection MYSQLI // Create Connection with Pdo\ $dsn = "mysql:host=localhost; dbname=test;"; $db_user = "root"; $db_password = ""; try{     $conn = new PDO("$dsn", "$db_user","$db_password");    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);     // $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);     echo "Connected"; }catch(PDOException $a){     echo "Connection Failed". $a->getMessage(); }