By GokiSoft.com|
20:28 30/09/2022|
AngularJS
[Source Code] Dự án quản lý phản hồi AngularJS - C2206L
#vidu2.html
<!DOCTYPE html>
<html ng-app="MyApp">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.1/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.1/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<title>AngularJS for beginner</title>
</head>
<body ng-controller="MyController">
<div class="container">
<div class="card mt-3">
<div class="card-header bg-info text-white">
CONTACT US
</div>
<div class="card-body">
<form method="post" ng-submit="saveData()">
<div class="form-group mb-3">
<label>Full Name: </label>
<input required type="text" name="fullname" class="form-control" placeholder="Enter fullnane" ng-model="fname">
</div>
<div class="form-group mb-3">
<label>Email: </label>
<input required type="email" name="email" class="form-control" placeholder="Enter email" ng-model="email">
</div>
<div class="form-group mb-3">
<label>Phone Number: </label>
<input required type="telno" name="phone" class="form-control" placeholder="Enter phone" ng-model="phone">
</div>
<div class="form-group mb-3">
<label>Subject: </label>
<input required type="text" name="subject" class="form-control" placeholder="Enter subject" ng-model="subject">
</div>
<div class="form-group mb-3">
<label>Message: </label>
<textarea required rows="5" class="form-control" ng-model="msg"></textarea>
</div>
<div class="form-group mb-3">
<button class="btn btn-success">Save Data</button>
<button class="btn btn-warning" type="button" ng-click="resetData()">Reset Form</button>
</div>
</form>
</div>
</div>
<div class="card mt-3">
<div class="card-header bg-warning text-white">
CONTACT MANAGEMENT
</div>
<div class="card-body">
<table class="table table-bordered table-hover mt-3">
<thead>
<tr>
<th>STT</th>
<th>Full Name</th>
<th>Email</th>
<th>Phone</th>
<th>Subject</th>
<th>Message</th>
<th style="width: 50px;"></th>
<th style="width: 50px;"></th>
</tr>
</thead>
<tbody>
<tr ng-repeat="item in feedbackList">
<td>{{ $index + 1 }}</td>
<td>{{ item.fullname }}</td>
<td>{{ item.email }}</td>
<td>{{ item.phone }}</td>
<td>{{ item.subject }}</td>
<td>{{ item.message }}</td>
<td>
<button class="btn btn-warning" ng-click="editItem($index)">Edit</button>
</td>
<td>
<button class="btn btn-danger" ng-click="deleteItem($index)">Delete</button>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<script type="text/javascript">
var app = angular.module('MyApp', [])
app.controller('MyController', ['$scope', function ($scope) {
$scope.feedbackList = []
$scope.currIndex = -1
$scope.saveData = function() {
var data = {
"fullname": $scope.fname,
"email": $scope.email,
"phone": $scope.phone,
"subject": $scope.subject,
"message": $scope.msg
}
if($scope.currIndex >= 0) {
$scope.feedbackList[$scope.currIndex] = data
$scope.currIndex = -1
} else {
$scope.feedbackList.push(data)
}
}
$scope.deleteItem = function(index) {
var option = confirm('Are you sure to delete this item?')
if(!option) return
$scope.feedbackList.splice(index, 1)
}
$scope.editItem = function(index) {
$scope.currIndex = index
$scope.fname = $scope.feedbackList[index].fullname
$scope.email = $scope.feedbackList[index].email
$scope.phone = $scope.feedbackList[index].phone
$scope.subject = $scope.feedbackList[index].subject
$scope.msg = $scope.feedbackList[index].message
}
$scope.resetData = function() {
$scope.fname = ""
$scope.email = ""
$scope.phone = ""
$scope.subject = ""
$scope.msg = ""
}
}])
</script>
</body>
</html>
Tags:
Phản hồi từ học viên
5
(Dựa trên đánh giá ngày hôm nay)