Angular function - angularjs

I need to execute a function inside ng-repeat to convert date. How can i parse a angular result in a function?
Field name in database is dataf
I tried diferent ways but no one works...
<tr ng-repeat="detail in details| filter:search_query">
<td><b>{{detail.nom}}</b></td>
<td>{{detail.descripcio}}</td>
<td>{{datareves(detail.datafet) }} </td>
<td>{{detail.visible}}</td>
and
getInfo();
function getInfo(){
$http.post('empDetails.php').success(function(data){
$scope.details = data;
});
}
$scope.datareves = function(details.datafet) {
var res = dataf.split(" ");
var res2 = res[0].split("-");
var final = res2[2] + "-" + res2[1] + "-" + res2[0];
return (final);
};

Your function should look like this
$scope.datareves = function(dataf) {
var res = dataf.split(" ");
var res2 = res[0].split("-");
var final = res2[2] + "-" + res2[1] + "-" + res2[0];
return (final);
};
notice the change to the first line. The name of the variable you used in the function was not the same as the name being passed into the function.
You can read more about javascript function definitions here https://www.w3schools.com/js/js_function_definition.asp

Related

Why is my Array returning a partial value?

I am trying to use textFinder to return the data from recordsSheet; I expect cslData[0] to return the employee ID number; however, it is returning the character in the 0 position of the string value.
function textFinder(findID){
var recordData;
var findRecord = recordsSheet.createTextFinder(findID);
var foundRange = findRecord.findNext();
var fRng = recordsSheet.getRange(foundRange.getRow(),1,1,9)
while(null != foundRange){
recordData.push(fRng.getValues());
foundRange = findRecord.findNext();
}
return(recordData);
}
var ss = SpreadsheetApp.getActiveSpreadsheet();
var recordsSheet = ss.getSheetByName("Active Records");
function onFormSubmit(e) {
var eRng = e.range;
var eRow = eRng.getRow();
var colA = ss.getRange('A' + eRow).getValue()
//The second value of the form response (e) is in Column A
Logger.log("Call txt finder")
var cslData = textFinder(colA).toString().split(",").join();
Logger.log("cslData: " + cslData)
Logger.log("cslData[0]: " + cslData[0])
Logger.log("cslData[1]: " + cslData[1])
Logger.log("cslData[2]: " + cslData[2])
Logger.log("cslData[0][0]: " + cslData[0][0])
}
I was expecting cslData[0] to return "100###5"
Modification points:
In your script, eRow is not declared. And, e is not used. Please be careful about this. In this modification, it supposes that eRow is declared elsewhere.
In your script, var recordData; is not an array. So, I think that an error occurs at recordData.push(fRng.getValues());. So, I'm worried that your showing script might be different from your tested script.
If var recordData; is var recordData; = [], about your current issue, in your script, the array of recordData is converted to the string by var cslData = textFinder(colA).toString().split(",").join();. By this, cslData[0] returns the top character. I thought that this is the reason for your issue.
And, if var recordData; is var recordData; = [], recordData is 3 dimensional array.
In your situation, I thought that findAll might be useful.
When these points are reflected in your script, how about the following modification?
Modified script:
var ss = SpreadsheetApp.getActiveSpreadsheet();
var recordsSheet = ss.getSheetByName("Active Records");
function textFinder(findID) {
return recordsSheet
.createTextFinder(findID)
.findAll()
.map(r => recordsSheet.getRange(r.getRow(), 1, 1, 9).getValues()[0]);
}
function onFormSubmit(e) {
var colA = ss.getRange('A' + eRow).getValue();
var cslData = textFinder(colA);
Logger.log("cslData: " + cslData);
if (cslData.length > 0) Logger.log("cslData[0]: " + cslData[0][0]);
}
or, I think that you can also the following script.
function onFormSubmit() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var recordsSheet = ss.getSheetByName("Active Records");
var eRow = ###; // Please set this.
var findID = ss.getRange('A' + eRow).getValue();
var cslData = recordsSheet.createTextFinder(findID).findAll().map(r => recordsSheet.getRange(r.getRow(), 1, 1, 9).getValues()[0]);
Logger.log("cslData: " + cslData)
if (cslData.length > 0) Logger.log("cslData[0]: " + cslData[0][0])
}
Reference:
findAll()

remove slash from $location.url() in angular

I need to get the GET params from url and pass it in the links to view in angular
I got from location.url() => "/?x=1&b=2"
but I need to get = > "?x=1&b=2" without slash
I tried to do that like the following:
var str = $location.url();
var x = str.replace(/\\/g, '');
but it kept the slash
var str = $location.url().substr(1);
Suggestion:
if you use route get the parameters with $routeParams
you can access the params like:
$routeParams.x
Answer to question:
Do it like a famous question suggests:
How can I get query string values in JavaScript?
function getParameterByName(name, url) {
if (!url) {
url = window.location.href;
}
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
To be used like:
var x = getParameterByName('x');

Using Alasql can you replace null column with empty string

In my angular controller i have ExportToExcel function, which is using alasql to export data to Excel and the data is coming from angular array.
The issue is the array might contains null as data, is it a way to replace null to empty string in alasql
Following is the function
ac.ExportToExcel = function () {
var time = new Date().toJSON().slice(0, 10);
alasql('SELECT * INTO XLSX("ExchangeReport' + time + '.xlsx",{headers:true}) FROM ? WHERE BillingPeriod = "' + ac.ExchangeReport.BillingPeriod + '" or "' + ac.ExchangeReport.BillingPeriod + '" = "" ', [ac.ExchangeDatas]);
}
And this is my data source
ac.ExchangeDatas = [];
from
ac.GetAllExchangeData = function () {
AccountRepository.GetAllExchangeData().$promise.then(
function (data) {
ac.ExchangeDatas = data.result;
},
function (err) {
console.log("error in GetAllExchangeData : " + err);
}
);
}
Data in excel:
var old = JSON.stringify($scope.achData).replace(/null/g, '""'); //convert to
JSON string and puts empty string in place of null values
var newArray = JSON.parse(old); //convert back to array
alasql('select * into XLSX("amar.xlsx", {headers:true}) from ?', [newArray]);
You should be able to use COALESCE, though you need to list all the columns like COALESCE(YourColumn,'') AS YourColumn instead of *. See https://github.com/agershun/alasql/wiki/Coalesce

In AngularJs set a variable in forEach for each object

I am trying to run a forEach function with data from a query and I want to set a variable for each object in that data to be able to use in a ng-repeat. I keep overriding the variable and cannot wrap my head around setting the variable for each one.
CategoryCardService.query({}, function (data) {
$scope.categoryCards = data;
angular.forEach(data, function (value) {
var categoryOccupancyPercent = $filter('number')(value.occupancy_percent * 100, 0);
var categoryTotalTurnover = value.total_turnover;
var doughnut_chart_min = 0;
var doughnut_chart_max = 0;
doughnut_chart_min = categoryOccupancyPercent;
doughnut_chart_max = 100 - categoryOccupancyPercent;
data.doughnutData = [doughnut_chart_min, doughnut_chart_max];
data.display = categoryOccupancyPercent + '%';
});
});
Pass in the key and assign like that.
CategoryCardService.query({}, function (data) {
$scope.categoryCards = data;
angular.forEach(data, function (value, key) {
// ...
data[key].display = categoryOccupancyPercent + '%';
});
});

jquery array return in function

I have a Jquery for Password-correction and it works fine, if I use the 2 Lines
// $('#minimum span').show();
// $('#minimum').addClass('boldgreen');
But I´ve tryed to put that out in a seperat function, and the return is what I want, if I alert(ret[0]);
But it doesn´t change the css in the html code.
I´ve tryed many ways, but without any result.
Any suggestions?
Thanks in advance.
var cssPassword = function(cssId, cssClass, hideShow, removeAddClass)
{
var IDKlasse = "$('" + cssId + " span')." + hideShow +"();";
var cssKlasse = "$('" + cssId + "')." + removeAddClass + "('" + cssClass + "');";
var cssArray = new Array();
cssArray[0] = IDKlasse;
cssArray[1] = cssKlasse;
return cssArray;
}
function()
...
if(passwordNew.length > 7) {
var ret = cssPassword('#minimum', 'green', 'show', 'addClass');
//eval(ret[0]);
//eval(ret[1]);
strength += 1;
alert(ret[1]);
// $('#minimum span').show();
// $('#minimum').addClass('boldgreen');
}else{
...

Resources