*Hi*
*i have try here to pass data from view to controller i try here to add
items to invoice throw click button "Ada Item" and after add all buttons i
will click on "Save button" to let me save it in database, but here i can't
get values from my view in my controller *
*js code:*
(function () {
var app = angular.module('jqanim', []).directive('jqAnimate', function
() {
return function (scope, instanceElement) {
setTimeout(function () {
instanceElement.show('slow');
}, 0);
}
});
app.controller('InvoiceController', function ($scope, $http) {
$scope.logoRemoved = false;
$scope.printMode = false;
var sample_invoice = {
tax: 13.00,
invoice_number: 10,
customer_info: {
name: "Mr. John Doe",
web_link: "John Doe Designs Inc.",
address1: "1 Infinite Loop",
address2: "Cupertino, California, US",
postal: "90210"
},
company_info: {
name: "Metaware Labs",
web_link: "www.metawarelabs.com",
address1: "123 Yonge Street",
address2: "Toronto, ON, Canada",
postal: "M5S 1B6"
},
items: [{ Quantity: 10, ProductID: 1, Discount: 9.95 }]
};
if (localStorage["invoice"] == "" || localStorage["invoice"] ==
null) {
$scope.invoice = sample_invoice;
} else {
$scope.invoice = JSON.parse(localStorage["invoice"]);
}
// Add
$scope.addItem = function () {
$scope.invoice.items.push({ Quantity: 0, Discount: 0,
ProductID: "" });
}
// save to database
$scope.save = function () {
$http.post("/api/customerService",
$scope.invoice.items).success(function (data) {
$scope.invoice.items.push(data);
});
};
// Remove
$scope.removeItem = function (item) {
$scope.invoice.items.splice($scope.invoice.items.indexOf(item),
1);
}
//Total
$scope.invoice_sub_total = function () {
var total = 0.00;
angular.forEach($scope.invoice.items, function (item, key) {
total += (item.Quantity * item.Discount);
});
return total;
}
// Tax
$scope.calculate_tax = function () {
return (($scope.invoice.tax * $scope.invoice_sub_total()) /
100);
}
// Grand Total
$scope.calculate_grand_total = function () {
localStorage["invoice"] = JSON.stringify($scope.invoice);
return $scope.calculate_tax() + $scope.invoice_sub_total();
}
// Print
$scope.printInfo = function () {
window.print();
}
// Reset Invoice
$scope.clearLocalStorage = function () {
var confirmClear = confirm("Are you sure you would like to
clear the invoice?");
if (confirmClear) {
localStorage["invoice"] = "";
$scope.invoice = sample_invoice;
}
}
});
})();
*view code:*
@model Angularjs_Invoice.Models.DB.Product
@{
ViewBag.Title = "Home Page";
}
<div class="container" width="800px" id="invoice" ng-app="jqanim"
ng-controller="InvoiceController">
<br />
<table class="table">
<tbody>
<tr>
<td align="center"
style="background-color:#357EBD;color:#FFF" colspan="2">
INVOICE
</td>
</tr>
</tbody>
</table>
@* Master *@
<table class="table">
<tr>
<td>
<div class="infos">
<div>
<strong>
<input type="text" class="form-control"
ng-model="invoice.customer_info.name" />
</strong>
</div>
</div>
</td>
<td align="right">
<div class="align-right">
<div>
<strong>
<input type="text" class="form-control"
ng-model="invoice.company_info.name" />
</strong>
</div>
</div>
</td>
</tr>
</table>
<form method="post" ng-submit="save(); invoice.items={}">
@* Details *@
<table class="table table-striped" align="center" dir="rtl">
<tr ng-hide="printMode">
<td colspan="5">
<a class="btn btn-primary" href ng-click="addItem()"
style="font-weight:bold;">Add Item</a>
</td>
</tr>
<tr>
<th class="text-center">الصنف</th>
<th class="text-center">الكمية</th>
<th class="text-center">السعر</th>
<th class="text-center">الإجمالى</th>
<th></th>
</tr>
<tr ng-repeat="item in invoice.items" style="display: none"
jq:animate="dropdown;250">
<td align="center">
@(Html.Kendo()
.DropDownList()
.Name("ProductID")
.BindTo(new List<string>()
{
"S - 6 3/4\"",
"M - 7 1/4\"",
"L - 7 1/8\"",
"XL - 7 5/8\""
})
.HtmlAttributes(new { ng_model = "item.ProductID"
})
)
</td>
<td align="center">
<input class="text-center form-control"
ng-model="item.Quantity" value="1" size="4" ng:required
ng:validate="integer" placeholder="Quantity" style="width:50px;">
</td>
<td align="center">
<input class="text-center form-control"
ng-model="item.Discount" value="0.00" ng:required ng:validate="number"
size="6" placeholder="Discount" style="width:50px;">
</td>
<td class="text-center" style="vertical-align:middle">
{{item.Discount * item.Quantity | currency}}
</td>
<td class="text-center">
<a href ng-hide="printMode" ng-click="removeItem(item)"
class="btn btn-danger">[X]</a>
</td>
</tr>
</table>
<input type="submit" name="submitbtn" value="Save" class="btn" />
</form>
@* Totals *@
<table class="table table-striped">
<tr>
<td align="left" style="width:150px;">
Sub Total
</td>
<td align="left">
{{invoice_sub_total() | currency}}
</td>
</tr>
<tr>
<td align="left" style="width:150px;">
Tax(%):
<input ng:model="invoice.tax" ng:validate="number"
style="background-color: #F9F9F9; border: 1px solid #F9F9F9; width:43px;"
class="text-center">
</td>
<td align="left">
{{calculate_tax() | currency}}
</td>
</tr>
<tr>
<td align="left" style="width:150px;">
Grand Total:
</td>
<td align="left">
{{calculate_grand_total() | currency}}
</td>
</tr>
</table>
@* Buttons *@
<div class="noPrint">
<a href="#" class="btn btn-primary" ng-show="printMode"
ng-click="printInfo()">Print</a>
<a href="#" class="btn btn-primary"
ng-click="clearLocalStorage()">Reset</a>
<a href="#" class="btn btn-primary" ng-hide="printMode"
ng-click="printMode = true;">Turn On Print Mode</a>
<a href="#" class="btn btn-primary" ng-show="printMode"
ng-click="printMode = false;">Turn Off Print Mode</a>
</div>
</div>
@section scripts{
<script src="~/Scripts/angular.js"></script>
<script src="~/Scripts/main.js"></script>
}
*controller code:*
namespace Angularjs_Invoice.Controllers
{
public class CustomerServiceController : ApiController
{
Model1 db = new Model1();
public Order_Detail Post(Order_Detail newCustomer)
{
if (newCustomer != null)
{
db.Order_Details.Add(newCustomer);
db.SaveChanges();
}
return null;
}
}
}
*so please how can i get values from my view in my controller as my code ?*
*Thanks a lot ...*
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.