dwilbank dwilbank - 2 months ago 9
JSON Question

What is this flood of errors in the console when I try to use ng-change?

They are

regularInterceptedExpression
errors.

I want the user to be able to paste properly formatted JSON into the text area in the left column, and have it auto-parsed, manipulated, and displayed in the right column.

(Right now, the JSON is hard coded into the controller, and it is being parsed correctly)

code - https://jsbin.com/gazecu/edit?html,js,console,output

P.S. Properly formatted JSON can be found in
$scope.rawData
below

angular
.module('XMLConverter', [])
.controller('XMLController', XMLControllerFn);

function XMLControllerFn($scope){

$scope.rawData = {
"JOB": {
"-PRO_JOB": "D6C1608473",
"-NOSAMS": "4",
"-PROCSTATUS": "161",
"-PROCSTATUS_TEXT": "Job Complete",
"-CLI_CODE": "24.0",
"-CLI_NAME": "4 HOURLY FLOT FEED/TAIL CON LEACH",
"-CONT_CODE": "PROCESS_MANAGER",
"-RECEIVED": "18/09/2016 16:23:06",
"-REQUIRED": "19/09/2016 16:00:00",
"-COMPLETED": "18/09/2016 16:59:37",
"-FIRSTREPORTED": "18/09/2016 16:59:37",
"-LASTREPORTED": "18/09/2016 16:59:37",
"-INVOICED": "18/09/2016 16:59:37",
"-CCLAS_LABCODE": "UAPREP",
"-XMLMODE": "REPORT",
"SAMPLE": [
{
"-CUID": "0001347486",
"-SAMPLETYPE": "OTHER",
"-SAMPLEIDENT": "1608473-2",
"-SAMPLETIME": "18/09/2016 1100",
"-EXTERNALIDENT": "FLOT_FEED",
"SCHEME": [
{
"-SCH_CODE": "/CSA",
"-SCHEMETYPE": "ANALYS",
"-SCHEMENAME": "/CSA",
"-SHORTNAME": "/CSA",
"ANALYTE": {
"-ANALYTECODE": "S",
"-ANALYTENAME": "S",
"-PI_TAG": "HV_FLOT_FEED_CNTLSOLID_S_pct",
"-NUMERICVALUE": "1.023800015449524",
"-ROUNDEDVALUE": "1.02",
"-REPDETLIMIT": "0.01",
"-ANALYTESTATUS": "AP",
"-REPUNITCODE": "%",
"-UNITNAME": "%",
"-QCMINVALUE": "NULL",
"-QCMAXVALUE": "42",
"-QCEXPECTEDVALUE": "0",
"-REPORTACTIVE": "-1",
"-QCACTIVE": "-1",
"-SCHSEQUENCE": "1",
"-ANASEQUENCE": "4",
"-STARTED": "18/09/2016 16:58:27",
"-COMPLETED": "18/09/2016 16:58:27"
}
},
{
"-SCH_CODE": "/GRAV",
"-SCHEMETYPE": "ANALYS",
"-SCHEMENAME": "/GRAV",
"-SHORTNAME": "/GRAV",
"ANALYTE": {
"-ANALYTENAME": "DrySample",
"-NUMERICVALUE": "0.239999994635582",
"-ROUNDEDVALUE": "0.240",
"-REPDETLIMIT": "0.001",
"-ANALYTESTATUS": "AP",
"-REPUNITCODE": "Kg",
"-UNITNAME": "Kg",
"-QCMINVALUE": "NULL",
"-QCMAXVALUE": "5000",
"-QCEXPECTEDVALUE": "0",
"-REPORTACTIVE": "-1",
"-QCACTIVE": "-1",
"-SCHSEQUENCE": "2",
"-ANASEQUENCE": "3",
"-STARTED": "18/09/2016 16:58:27",
"-COMPLETED": "18/09/2016 16:58:27"
}
},
{
"-SCH_CODE": "AR01/AA",
"-SCHEMETYPE": "ANALYS",
"-SCHEMENAME": "AR01/AA",
"-SHORTNAME": "AR01/AA",
"ANALYTE": {
"-ANALYTECODE": "AG",
"-ANALYTENAME": "Ag",
"-PI_TAG": "HV_FLOT_FEED_CNTLSOLID_Ag_ppm",
"-NUMERICVALUE": "14.90999984741211",
"-ROUNDEDVALUE": "14.9",
"-REPDETLIMIT": "0.5",
"-ANALYTESTATUS": "AP",
"-REPUNITCODE": "ppm",
"-UNITNAME": "ppm",
"-QCMINVALUE": "NULL",
"-QCMAXVALUE": "100",
"-QCEXPECTEDVALUE": "0",
"-REPORTACTIVE": "-1",
"-QCACTIVE": "-1",
"-SCHSEQUENCE": "3",
"-ANASEQUENCE": "2",
"-STARTED": "18/09/2016 16:58:27",
"-COMPLETED": "18/09/2016 16:58:27"
}
},
{
"-SCH_CODE": "FA25/AA",
"-SCHEMETYPE": "ANALYS",
"-SCHEMENAME": "FA25/AA",
"-SHORTNAME": "FA25/AA",
"ANALYTE": {
"-ANALYTECODE": "AU",
"-ANALYTENAME": "Au",
"-PI_TAG": "HV_FLOT_TAIL_CNTLSOLID_Au_g/t",
"-NUMERICVALUE": "1.149999976158142",
"-ROUNDEDVALUE": "1.15",
"-REPDETLIMIT": "0.01",
"-ANALYTESTATUS": "AP",
"-REPUNITCODE": "g/t",
"-UNITNAME": "g/t",
"-QCMINVALUE": "NULL",
"-QCMAXVALUE": "1000",
"-QCEXPECTEDVALUE": "0",
"-REPORTACTIVE": "-1",
"-QCACTIVE": "-1",
"-SCHSEQUENCE": "4",
"-ANASEQUENCE": "1",
"-STARTED": "18/09/2016 16:58:27",
"-COMPLETED": "18/09/2016 16:58:27"
}
}
]
},
{
"-CUID": "0001347487",
"-SAMPLETYPE": "OTHER",
"-SAMPLEIDENT": "1608473-3",
"-SAMPLETIME": "18/09/2016 1100",
"-EXTERNALIDENT": "FLOT_TAIL",
"SCHEME": [
{
"-SCH_CODE": "/CSA",
"-SCHEMETYPE": "ANALYS",
"-SCHEMENAME": "/CSA",
"-SHORTNAME": "/CSA",
"ANALYTE": {
"-ANALYTECODE": "S",
"-ANALYTENAME": "S",
"-PI_TAG": "HV_FLOT_TAIL_CNTLSOLID_S_pct",
"-NUMERICVALUE": "0.7418000102043152",
"-ROUNDEDVALUE": "0.74",
"-REPDETLIMIT": "0.01",
"-ANALYTESTATUS": "AP",
"-REPUNITCODE": "%",
"-UNITNAME": "%",
"-QCMINVALUE": "NULL",
"-QCMAXVALUE": "42",
"-QCEXPECTEDVALUE": "0",
"-REPORTACTIVE": "-1",
"-QCACTIVE": "-1",
"-SCHSEQUENCE": "1",
"-ANASEQUENCE": "4",
"-STARTED": "18/09/2016 16:58:27",
"-COMPLETED": "18/09/2016 16:58:27"
}
},
{
"-SCH_CODE": "/GRAV",
"-SCHEMETYPE": "ANALYS",
"-SCHEMENAME": "/GRAV",
"-SHORTNAME": "/GRAV",
"ANALYTE": {
"-ANALYTENAME": "DrySample",
"-NUMERICVALUE": "0.2199999988079071",
"-ROUNDEDVALUE": "0.220",
"-REPDETLIMIT": "0.001",
"-ANALYTESTATUS": "AP",
"-REPUNITCODE": "Kg",
"-UNITNAME": "Kg",
"-QCMINVALUE": "NULL",
"-QCMAXVALUE": "5000",
"-QCEXPECTEDVALUE": "0",
"-REPORTACTIVE": "-1",
"-QCACTIVE": "-1",
"-SCHSEQUENCE": "2",
"-ANASEQUENCE": "3",
"-STARTED": "18/09/2016 16:58:27",
"-COMPLETED": "18/09/2016 16:58:27"
}
},
{
"-SCH_CODE": "AR01/AA",
"-SCHEMETYPE": "ANALYS",
"-SCHEMENAME": "AR01/AA",
"-SHORTNAME": "AR01/AA",
"ANALYTE": {
"-ANALYTECODE": "AG",
"-ANALYTENAME": "Ag",
"-PI_TAG": "HV_FLOT_TAIL_CNTLSOLID_Ag_ppm",
"-NUMERICVALUE": "3.674999713897705",
"-ROUNDEDVALUE": "3.7",
"-REPDETLIMIT": "0.5",
"-ANALYTESTATUS": "AP",
"-REPUNITCODE": "ppm",
"-UNITNAME": "ppm",
"-QCMINVALUE": "NULL",
"-QCMAXVALUE": "100",
"-QCEXPECTEDVALUE": "0",
"-REPORTACTIVE": "-1",
"-QCACTIVE": "-1",
"-SCHSEQUENCE": "3",
"-ANASEQUENCE": "2",
"-STARTED": "18/09/2016 16:58:27",
"-COMPLETED": "18/09/2016 16:58:27"
}
},
{
"-SCH_CODE": "FA25/AA",
"-SCHEMETYPE": "ANALYS",
"-SCHEMENAME": "FA25/AA",
"-SHORTNAME": "FA25/AA",
"ANALYTE": {
"-ANALYTENAME": "Au",
"-NUMERICVALUE": "0.1599999964237213",
"-ROUNDEDVALUE": "0.16",
"-REPDETLIMIT": "0.01",
"-ANALYTESTATUS": "AP",
"-REPUNITCODE": "g/t",
"-UNITNAME": "g/t",
"-QCMINVALUE": "NULL",
"-QCMAXVALUE": "1000",
"-QCEXPECTEDVALUE": "0",
"-REPORTACTIVE": "-1",
"-QCACTIVE": "-1",
"-SCHSEQUENCE": "4",
"-ANASEQUENCE": "1",
"-STARTED": "18/09/2016 16:58:27",
"-COMPLETED": "18/09/2016 16:58:27"
}
}
]
},
{
"-CUID": "0001347488",
"-SAMPLETYPE": "OTHER",
"-SAMPLEIDENT": "1608473-4",
"-SAMPLETIME": "18/09/2016 1100",
"-EXTERNALIDENT": "CONC_LEACH_FEED",
"SCHEME": [
{
"-SCH_CODE": "/CSA",
"-SCHEMETYPE": "ANALYS",
"-SCHEMENAME": "/CSA",
"-SHORTNAME": "/CSA",
"ANALYTE": {
"-ANALYTECODE": "S",
"-ANALYTENAME": "S",
"-PI_TAG": "HV_CONC_LEACH_FEED_CNTLSOLID_S_pct",
"-NUMERICVALUE": "7.076700210571289",
"-ROUNDEDVALUE": "7.08",
"-REPDETLIMIT": "0.01",
"-ANALYTESTATUS": "AP",
"-REPUNITCODE": "%",
"-UNITNAME": "%",
"-QCMINVALUE": "NULL",
"-QCMAXVALUE": "42",
"-QCEXPECTEDVALUE": "0",
"-REPORTACTIVE": "-1",
"-QCACTIVE": "-1",
"-SCHSEQUENCE": "1",
"-ANASEQUENCE": "4",
"-STARTED": "18/09/2016 16:58:27",
"-COMPLETED": "18/09/2016 16:58:27"
}
},
{
"-SCH_CODE": "/GRAV",
"-SCHEMETYPE": "ANALYS",
"-SCHEMENAME": "/GRAV",
"-SHORTNAME": "/GRAV",
"ANALYTE": {
"-ANALYTENAME": "DrySample",
"-NUMERICVALUE": "0.2800000011920929",
"-ROUNDEDVALUE": "0.280",
"-REPDETLIMIT": "0.001",
"-ANALYTESTATUS": "AP",
"-REPUNITCODE": "Kg",
"-UNITNAME": "Kg",
"-QCMINVALUE": "NULL",
"-QCMAXVALUE": "5000",
"-QCEXPECTEDVALUE": "0",
"-REPORTACTIVE": "-1",
"-QCACTIVE": "-1",
"-SCHSEQUENCE": "2",
"-ANASEQUENCE": "3",
"-STARTED": "18/09/2016 16:58:27",
"-COMPLETED": "18/09/2016 16:58:27"
}
},
{
"-SCH_CODE": "AR01/AA",
"-SCHEMETYPE": "ANALYS",
"-SCHEMENAME": "AR01/AA",
"-SHORTNAME": "AR01/AA",
"ANALYTE": {
"-ANALYTECODE": "AG",
"-ANALYTENAME": "Ag",
"-PI_TAG": "HV_CONC_LEACH_FEED_CNTLSOLID_Ag_ppm",
"-NUMERICVALUE": "169.8899993896484",
"-ROUNDEDVALUE": "169.9",
"-REPDETLIMIT": "0.5",
"-ANALYTESTATUS": "AP",
"-REPUNITCODE": "ppm",
"-UNITNAME": "ppm",
"-QCMINVALUE": "NULL",
"-QCMAXVALUE": "100",
"-QCEXPECTEDVALUE": "0",
"-REPORTACTIVE": "-1",
"-QCACTIVE": "-1",
"-SCHSEQUENCE": "3",
"-ANASEQUENCE": "2",
"-STARTED": "18/09/2016 16:58:27",
"-COMPLETED": "18/09/2016 16:58:27"
}
},
{
"-SCH_CODE": "FA25/AA",
"-SCHEMETYPE": "ANALYS",
"-SCHEMENAME": "FA25/AA",
"-SHORTNAME": "FA25/AA",
"ANALYTE": {
"-ANALYTECODE": "AU",
"-ANALYTENAME": "Au",
"-PI_TAG": "HV_CONC_LEACH_FEED_CNTLSOLID_Au_g/t",
"-NUMERICVALUE": "10.96000003814697",
"-ROUNDEDVALUE": "10.96",
"-REPDETLIMIT": "0.01",
"-ANALYTESTATUS": "AP",
"-REPUNITCODE": "g/t",
"-UNITNAME": "g/t",
"-QCMINVALUE": "NULL",
"-QCMAXVALUE": "1000",
"-QCEXPECTEDVALUE": "0",
"-REPORTACTIVE": "-1",
"-QCACTIVE": "-1",
"-SCHSEQUENCE": "4",
"-ANASEQUENCE": "1",
"-STARTED": "18/09/2016 16:58:27",
"-COMPLETED": "18/09/2016 16:58:27"
}
}
]
},
{
"-CUID": "0001347489",
"-SAMPLETYPE": "OTHER",
"-SAMPLEIDENT": "1608473-5",
"-SAMPLETIME": "18/09/2016 1100",
"-EXTERNALIDENT": "CONC_LEACH_TK1",
"SCHEME": [
{
"-SCH_CODE": "/GRAV",
"-SCHEMETYPE": "ANALYS",
"-SCHEMENAME": "/GRAV",
"-SHORTNAME": "/GRAV",
"ANALYTE": {
"-ANALYTENAME": "DrySample",
"-NUMERICVALUE": "0.2300000041723251",
"-ROUNDEDVALUE": "0.230",
"-REPDETLIMIT": "0.001",
"-ANALYTESTATUS": "AP",
"-REPUNITCODE": "Kg",
"-UNITNAME": "Kg",
"-QCMINVALUE": "NULL",
"-QCMAXVALUE": "5000",
"-QCEXPECTEDVALUE": "0",
"-REPORTACTIVE": "-1",
"-QCACTIVE": "-1",
"-SCHSEQUENCE": "2",
"-ANASEQUENCE": "3",
"-STARTED": "18/09/2016 16:58:27",
"-COMPLETED": "18/09/2016 16:58:27"
}
},
{
"-SCH_CODE": "AR01/AA",
"-SCHEMETYPE": "ANALYS",
"-SCHEMENAME": "AR01/AA",
"-SHORTNAME": "AR01/AA",
"ANALYTE": {
"-ANALYTECODE": "AG",
"-ANALYTENAME": "Ag",
"-PI_TAG": "HV_CONC_LEACH_TK1_CNTLSOLID_Ag_ppm",
"-NUMERICVALUE": "85.15499114990234",
"-ROUNDEDVALUE": "85.2",
"-REPDETLIMIT": "0.5",
"-ANALYTESTATUS": "AP",
"-REPUNITCODE": "ppm",
"-UNITNAME": "ppm",
"-QCMINVALUE": "NULL",
"-QCMAXVALUE": "100",
"-QCEXPECTEDVALUE": "0",
"-REPORTACTIVE": "-1",
"-QCACTIVE": "-1",
"-SCHSEQUENCE": "3",
"-ANASEQUENCE": "2",
"-STARTED": "18/09/2016 16:58:27",
"-COMPLETED": "18/09/2016 16:58:27"
}
},
{
"-SCH_CODE": "FA25/AA",
"-SCHEMETYPE": "ANALYS",
"-SCHEMENAME": "FA25/AA",
"-SHORTNAME": "FA25/AA",
"ANALYTE": {
"-ANALYTECODE": "AU",
"-ANALYTENAME": "Au",
"-PI_TAG": "HV_CONC_LEACH_TK1_CNTLSOLID_Au_g/t",
"-NUMERICVALUE": "3.599999904632568",
"-ROUNDEDVALUE": "3.60",
"-REPDETLIMIT": "0.01",
"-ANALYTESTATUS": "AP",
"-REPUNITCODE": "g/t",
"-UNITNAME": "g/t",
"-QCMINVALUE": "NULL",
"-QCMAXVALUE": "1000",
"-QCEXPECTEDVALUE": "0",
"-REPORTACTIVE": "-1",
"-QCACTIVE": "-1",
"-SCHSEQUENCE": "4",
"-ANASEQUENCE": "1",
"-STARTED": "18/09/2016 16:58:27",
"-COMPLETED": "18/09/2016 16:58:27"
}
}
]
}
]
}
};
$scope.sample = $scope.rawData.JOB.SAMPLE;
$scope.sampleTime = function() {
return 'Sampletime - ' + $scope.sample[0]['-SAMPLETIME'];
}

$scope.ObjArray = function(){
var sample = $scope.sample;
var ObjArr = [];
var obj;
angular.forEach(sample, function(sample) {
var scheme = sample['SCHEME'];
angular.forEach(scheme, function(x) {
obj= {};
obj.pi_tag = x.ANALYTE['-PI_TAG'] || 'undefined';
obj.num_value = x.ANALYTE['-NUMERICVALUE'];
ObjArr.push(obj);
})
})
return ObjArr;
}

$scope.processJSON = function(JSON){
console.log('new data');
$scope.rawData = JSON.parse(data);
}

}

Answer

You can't use functions in the view that will return a different value every time they are run

The digest cycle will run at least 2 times and more until the scope is stable.

ng-repeat="item in ObjArray()"

Because you return a new array each time this is run, the scope can never stabilize. Angular will run a maximum of 10 digests by default and then abort. That is the error you are seeing

Note that the output of the function may look the same each time it runs... 2 arrays are only equal when they reference the same array instance. [] != []


Create the array in the controller first and assign to a scope property, then use that to pass to ng-repeat

$scope.displayArray= $scope.ObjArray()
ng-repeat="item in displayArray"