当我尝试使用ng-change时,控制台中的这些错误是什么?

时间:2016-09-30 02:48:06

标签: angularjs json

他们是regularInterceptedExpression错误。

我希望用户能够将格式正确的JSON粘贴到左栏的文本区域,并在右栏中对其进行自动解析,操作和显示。

(现在,JSON被硬编码到控制器中,并且正在被正确解析)

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

P.S。可以在$scope.rawData下面找到格式正确的JSON

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);
  }

}

1 个答案:

答案 0 :(得分:3)

您不能在视图中使用每次运行时返回不同值的函数

摘要周期将至少运行2次,直到范围稳定为止。

ng-repeat="item in ObjArray()"

因为每次运行时都返回一个新数组,所以范围永远不会稳定。 Angular默认会运行最多10个摘要,然后中止。这是你看到的错误

请注意,每次运行时函数的输出可能看起来都相同... 2个数组在引用同一个数组实例时只相等。 [] != []

首先在控制器中创建数组并分配到范围属性,然后使用它传递给ng-repeat

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