Angularjs Angular js:无法遍历ng init动态数据
我对这个棱角分明的世界还不熟悉,请帮帮我 我有下表一行Angularjs Angular js:无法遍历ng init动态数据,angularjs,angularjs-ng-init,Angularjs,Angularjs Ng Init,我对这个棱角分明的世界还不熟悉,请帮帮我 我有下表一行 <tr data-ng-repeat="obj in myObjs | filter:search"> <td><strong data-ng-hide="obj.editMode">{{ obj.ObjID }}</strong></td> <td> <p data-ng-hide="obj.editMode">{{ obj.Key }}</
<tr data-ng-repeat="obj in myObjs | filter:search">
<td><strong data-ng-hide="obj.editMode">{{ obj.ObjID }}</strong></td>
<td>
<p data-ng-hide="obj.editMode">{{ obj.Key }}</p>
<p data-ng-show="obj.editMode">
<input type="text" data-ng-model="obj.Name" />
</p>
</td>
<td>
<p data-ng-hide="obj.editMode">{{ obj.Value }}</p>
<div ng-init="objKVP = {{obj.Value}}">
<ul class="example-animate-container">
<li class="animate-repeat" ng-repeat="val in objKVP">
{{val.Key}} : {{val.Value}}
</li>
</ul>
</div>
</td>
但是当我尝试获取键和值时,它不会填充在LI标记中。
如果我将上面的键值对直接放在objKVP中,那么它会在LI标记中显示键值,
因此,问题在于动态值(尽管它在我检查元素时显示)
帮助您可以尝试使用以下示例:
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
<script>
var myApp = angular.module('myApp', []);
myApp.controller('myController', [
'$scope', function($scope) {
$scope.init = function() {
$scope.a = 'Apples';
$scope.b = 'Bees';
$scope.c = 'Zebras';
$scope.objKVP = [
{ 'Key': 'test', 'Value': 'https://google.com' },
{ 'Key': 'test1', 'Value': 'testval1' },
{ 'Key': 'test2', 'Value': 't@testval2' },
{ 'Key': 'test3', 'Value': 'testval3' },
{ 'Key': 'test4', 'Value': 'testval3' }
];
};
// runs once per controller instantiation
$scope.init();
}
]);
</script>
<body ng-controller="myController">
<h2>JavaScript Projects</h2>
<br>
<h2 ng-bind="a+ ' ' + b +' ' +c "></h2>
<table>
<tr ng-repeat="obj in objKVP | filter:search">
<td><strong ng-hide="obj.editMode">{{ obj.ObjID }}</strong></td>
<td width="100px;">
<p ng-hide="obj.editMode">{{ obj.Key }}</p>
</td>
<td width="200px;">
<p ng-hide="obj.editMode">{{ obj.Value }}</p>
<p ng-show="obj.editMode">
<input type="text" ng-model="obj.Name" />
</p>
</td>
</tr>
</table>
</body>
var myApp=angular.module('myApp',[]);
myApp.controller('myController'[
“$scope”,函数($scope){
$scope.init=函数(){
$scope.a='Apples';
$scope.b='Bees';
$scope.c=‘斑马’;
$scope.objKVP=[
{'Key':'test','Value':'https://google.com' },
{'Key':'test1','Value':'testval1'},
{'Key':'test2','Value':'t@testval2' },
{'Key':'test3','Value':'testval3'},
{'Key':'test4','Value':'testval3'}
];
};
//每个控制器实例化运行一次
$scope.init();
}
]);
JavaScript项目
{{obj.ObjID}
{{obj.Key}
{{obj.Value}
为什么不直接使用ng repeat=“val in obj.Value”
而不是ng init
?我尝试了ng repeat,但它只返回了“:”
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
<script>
var myApp = angular.module('myApp', []);
myApp.controller('myController', [
'$scope', function($scope) {
$scope.init = function() {
$scope.a = 'Apples';
$scope.b = 'Bees';
$scope.c = 'Zebras';
$scope.objKVP = [
{ 'Key': 'test', 'Value': 'https://google.com' },
{ 'Key': 'test1', 'Value': 'testval1' },
{ 'Key': 'test2', 'Value': 't@testval2' },
{ 'Key': 'test3', 'Value': 'testval3' },
{ 'Key': 'test4', 'Value': 'testval3' }
];
};
// runs once per controller instantiation
$scope.init();
}
]);
</script>
<body ng-controller="myController">
<h2>JavaScript Projects</h2>
<br>
<h2 ng-bind="a+ ' ' + b +' ' +c "></h2>
<table>
<tr ng-repeat="obj in objKVP | filter:search">
<td><strong ng-hide="obj.editMode">{{ obj.ObjID }}</strong></td>
<td width="100px;">
<p ng-hide="obj.editMode">{{ obj.Key }}</p>
</td>
<td width="200px;">
<p ng-hide="obj.editMode">{{ obj.Value }}</p>
<p ng-show="obj.editMode">
<input type="text" ng-model="obj.Name" />
</p>
</td>
</tr>
</table>
</body>