I am using linq.js in AngularJs, I am using in many places and its working fine now I used in different place and it doesn't work for me. Not working means I am not achieving the desired result it always showing {}
. please take a look below code if I am doing something wrong.
var app = angular.module('testApp', ['angular.filter', 'angular-linq', 'ngSelect2']);
app.controller('testController', function ($scope, $http, $timeout, $q, $linq){
$scope.Vendors =
[
{VendorId:"VND001", VendorName:"Pharma Plus Pharmacy", Address:"Bahawalpur"},
{VendorId:"VND001", VendorName:"Pakistan Pharma", Address:"Bahawalpur"}
];
$scope.InvoiceItems =
[
{
VendorId:"VND001",
ItemName:"Gold Set Jewellery",
ItemDesc:"Some Description",
Cost:280.50,
Quantity:50
},
{
VendorId:"VND001",
ItemName:"First Class HandWatch",
ItemDesc:"Some Description",
Cost:100.50,
Quantity:50
},
{
VendorId:"VND002",
ItemName:"Gold Set Jewellery",
ItemDesc:"Some Description",
Cost:280.50,
Quantity:50
},
{
VendorId:"VND002",
ItemName:"First Class HandWatch",
ItemDesc:"Some Description",
Cost:100.50,
Quantity:50
},
];
$scope.totalAmount = function(vendorId){
return $linq.Enumerable().From($scope.InvoiceItems).Where("x => x.VendorId =="+vendorId).Select(function(x){
return (+x.Cost)*x.Quantity;
}).Sum();
}
}
}
Please take a look below html
<div class="row" ng-app="testApp">
<div class="col-xs-12" ng-controller="testController" ng-init="initializeDefault()">
<div ng-repeat="v in Vendors">
<div>{{ v.VendorId }}</div>
<div>{{ v.VendorName }}</div>
<div>{{ v.Address }}</div>
<div>{{ totalAmount(v.VendorId) }}</div>
</div>
</div>
</div>
Prompt response will be appreciated.