_>我需要的输出是这个....当我试图运行代码它不工作正常,当我使用for循环用于打印结果以HTML它工作正常,当我试图改变我的代码概念angularjs我不能把它说obj中的价值,而不是定义#对象并获得多个错误我的AngularJs代码不能正常工作得到这个错误 - TypeError:无法读取属性'#<Object>'undefined
I'm sharing my code
HTML:
<!DOCTYPE html>
<html ng-app="inputs">
<head>
<script data-require="[email protected]" data-semver="1.4.1" src="https://code.angularjs.org/1.4.1/angular.js"></script>
<script src="script.js"></script>
</head>
<body ng-controller="MainCtrl">
<div id="result" style="width:600px; text-transform: capitalize;" align="right">Heloo</div>
<div ng-repeat="component in components">
{{mylogic(component)}}
</div>
JS:
var app = angular.module("inputs",[]);
app.controller("MainCtrl",function($scope){
$scope.components=[{
'name':{
'fname':'{"placeholder":"First Name","description":"Enter First Name of the user","value":"abc","type":"text"}',
'lname':'{"placeholder":"Second Name","description":"Enter Last Name of the user","value":"ddd","type":"text"}'
},
'password':'{"placeholder":"Password","description":"Enter password","value":"","type":"password"}',
'dim':{
'dim2':{
'dim3':'{"placeholder":"Sample","description":"Enter sample text","value":"ssds"}'
}
},
'ary':{
'ar10':{
'ary2':{
'ary3':'{"placeholder":"Sample","description":"Enter sample text","value":"acb"}'
}
},
'ary11':''
}
}];
var result='';
$scope.mylogic=function(obj,source){
/* console.log(source);*/
/*console.log(obj,source);
console.log(typeof source[obj]);*/
if(typeof source[obj]=='string'){
var val=[];
if(source[obj]!=""){
val =JSON.parse(source[obj]);
return obj +' <input type="'+val.type+'" value="'+val.value+'" placeholder="'+val.placeholder+'" type="text" ><br><code>Notes* '+val.description+'</code> <hr>';
}else{
return obj +' <input placeholder="'+obj+'" type="text" > <hr>';
}
}else{ // console.log(components[obj]);
var subObj=source[obj]; var tempObj=[];
for(item in subObj){
// console.log(item,'--',subObj);
tempObj.push(obj+' > ' +mylogic(item,subObj) );
}
return tempObj;
/* console.log(tempObj);*/
}
}
/*for(component in $scope.components){
result+= mylogic(component,$scope.components);
console.log('Component',$scope.components[component]);
console.log(result+= mylogic(component,$scope.components));
console.log(mylogic);
}
*/
// console.log('Component',$scope.components[component]);
var res=document.getElementById('result');
res.innerHTML=result;
});
请清洁代码(删除注释行),并张贴堆栈跟踪。 – undefined
@JK_Jha:当我打印只是组件打印JSON数组..但是当我打印{{“mylogic(组件)”}}使用ng - 重复其不工作..帮助我,如果你可以 –
@AustinKootz: - 我发布输出时,当我得到的时候,我在纯javascript的同一个程序。我在这里卡住 –