OK, I have a controller where I need to use a function as a param
angular.module('myCtrl', function($scope) {
$scope.$on('lines:deselectLine', function(ev, slip) {
_.each($scope.lineItems, function(lineItem) {
_.each(lineItem, function(lineLeague) {
_.each(lineLeague, function(line) {
_.each(line.rows, function(row) {
if (row.nss + '' === slip.nss) {
var line = slip.line;
if (line === row.spread.line + '') {
row.spreadSelected = false;
}
if (line === row.total.line + '') {
row.totalSelected = false;
}
if (line === row.moneyLineId + '') {
row.moneyLineSelected = false;
}
}
});
});
});
});
});
});
this is the full function but I need to take this part away in a function
if (row.nss + '' === slip.nss) {
var line = slip.line;
if (line === row.spread.line + '') {
row.spreadSelected = false;
}
if (line === row.total.line + '') {
row.totalSelected = false;
}
if (line === row.moneyLineId + '') {
row.moneyLineSelected = false;
}
}
so at the end I will need something like this
angular.module('myCtrl', function($scope) {
$scope.$on('lines:deselectLine', function(ev, slip) {
_.each($scope.lineItems, function(lineItem) {
_.each(lineItem, function(lineLeague) {
_.each(lineLeague, function(line) {
_.each(line.rows, function(row, iWillBeFunctionParam) {
//SOMETHING NEW WILL HAPPEN HERE
});
});
});
});
});
$scope.iWillBeFunctionParam = function(slip) {
if (row.nss + '' === slip.nss) {
var line = slip.line;
if (line === row.spread.line + '') {
row.spreadSelected = false;
}
if (line === row.total.line + '') {
row.totalSelected = false;
}
if (line === row.moneyLineId + '') {
row.moneyLineSelected = false;
}
}
};
});
Be aware of the $scope.$on which is an $emit...
So, what should I do to use the new function as a Param ?
$scope.iWillBeFunctionParamdoesn't seem to have a closure it can referencelineorrowfrom. You will need to pass these in to it when it is invoked (add a couple parameters for them, invoke with them as arguments)