Discussion:
[AngularJS] How to use lodash or any alternative to angular.foreach in angular2
Rohit luthra
2016-05-17 12:30:51 UTC
Permalink
How to use lodash or any alternative to angular.foreach

var data = {
TimeStamp : "2016-04-25 12:50:00"
};
$http({
method: 'POST',
url: $location.protocol()+ '://' + $location.host() + ':' +
$location.port() + '/serverutilizationreport',
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
data: $httpParamSerializerJQLike(data),
}).success(function(data) {
$scope.pieData = [];
$scope.chartData = [];
$scope.requesttypes = [];
$scope.uniqrequesttypes = [];
$scope.transactionResponseTimeArray = [];
$scope.transactionCountArray = [];
$scope.totalRendererFailedTransactions;
$scope.totalRendererCompletions;
//$scope.requestcount = [];
*angular.forEach(data, function(record) {*
var rendererOutTime = record.RendererOutTime;
var rendererInTime = record.RendererInTime;
var requestURI = record.RequestURI;
var timeTakenMS = record.TimeTakenMS;
var errorMessage = record.ErrorMessage;
if(errorMessage && rendererOutTime && rendererInTime){
$scope.totalRendererFailedTransactions++;
}

if(rendererOutTime && rendererInTime){
$scope.totalRendererCompletions++;
}

if(requestURI && rendererOutTime && rendererInTime){
$scope.transactionResponseTimeArray.push(timeTakenMS);

$scope.transactionCountArray.push($scope.transactionResponseTimeArray.length)
nameSpace = requestURI.substring(1);
if(nameSpace.indexOf('/') != -1){
nameSpace= nameSpace.substring(0, nameSpace.indexOf('/'));
}
else if(nameSpace.indexOf('?') != -1){
nameSpace= nameSpace.substring(0, nameSpace.indexOf('?'));
}
else{
nameSpace= nameSpace.substring(0, nameSpace.length);
}
if(nameSpace){
if($scope.uniqrequesttypes.indexOf(nameSpace) == -1){
$scope.uniqrequesttypes.push(nameSpace);
}
$scope.requesttypes.push(nameSpace);
}
}
});
--
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 angular+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.
Carlos Esteban Lopez Jaramillo
2016-05-18 13:12:55 UTC
Permalink
You sure you mean Ng2? this code looks like Ng1 to me, Ng2 deleted the use
of the '$scope' variable, anyway the use is not that complex, just import
the lodash function you need and replace it where you need it:
angular.forEach(data, (record) => {...})
// If using the global way
_.each(data, (record) => {...})
// If using the specific import
each(data, (record) => {...})

The importing is up to your build process, if Ng1 most likely you just add
a script tag up in the html before your script tags, in Ng2 it can be done
the same, or you can import just that specific function.
Post by Rohit luthra
How to use lodash or any alternative to angular.foreach
var data = {
TimeStamp : "2016-04-25 12:50:00"
};
$http({
method: 'POST',
url: $location.protocol()+ '://' + $location.host() + ':' +
$location.port() + '/serverutilizationreport',
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
data: $httpParamSerializerJQLike(data),
}).success(function(data) {
$scope.pieData = [];
$scope.chartData = [];
$scope.requesttypes = [];
$scope.uniqrequesttypes = [];
$scope.transactionResponseTimeArray = [];
$scope.transactionCountArray = [];
$scope.totalRendererFailedTransactions;
$scope.totalRendererCompletions;
//$scope.requestcount = [];
*angular.forEach(data, function(record) {*
var rendererOutTime = record.RendererOutTime;
var rendererInTime = record.RendererInTime;
var requestURI = record.RequestURI;
var timeTakenMS = record.TimeTakenMS;
var errorMessage = record.ErrorMessage;
if(errorMessage && rendererOutTime && rendererInTime){
$scope.totalRendererFailedTransactions++;
}
if(rendererOutTime && rendererInTime){
$scope.totalRendererCompletions++;
}
if(requestURI && rendererOutTime && rendererInTime){
$scope.transactionResponseTimeArray.push(timeTakenMS);
$scope.transactionCountArray.push($scope.transactionResponseTimeArray.length)
nameSpace = requestURI.substring(1);
if(nameSpace.indexOf('/') != -1){
nameSpace= nameSpace.substring(0, nameSpace.indexOf('/'));
}
else if(nameSpace.indexOf('?') != -1){
nameSpace= nameSpace.substring(0, nameSpace.indexOf('?'));
}
else{
nameSpace= nameSpace.substring(0, nameSpace.length);
}
if(nameSpace){
if($scope.uniqrequesttypes.indexOf(nameSpace) == -1){
$scope.uniqrequesttypes.push(nameSpace);
}
$scope.requesttypes.push(nameSpace);
}
}
});
--
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 angular+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.
Carlos Esteban Lopez Jaramillo
2016-05-18 13:13:43 UTC
Permalink
You sure you mean Ng2? this code looks like Ng1 to me, Ng2 deleted the use
of the '$scope' variable, anyway the use is not that complex, just import
the lodash function you need and replace it where you need it:
angular.forEach(data, (record) => {...})
// If using the global way
_.each(data, (record) => {...})
// If using the specific import
each(data, (record) => {...})

The importing is up to your build process, if Ng1 most likely you just add
a script tag up in the html before your script tags, in Ng2 it can be done
the same, or you can import just that specific function.
--
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 angular+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.
Loading...