AngularJS循环不工作
AngularJS loop not working
在下面的代码中,硬编码的div运行良好。但是尝试使用angularJS渲染s,这在中不起作用
<!doctype html>
<html ng-app>
<head>
<title> AngularJS Tabs</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<style>
.box {
margin : 5px;
display : inline-block;
width: 150px;
height: 250px;
background-color: grey;
text-align:center;
vertical-align: top;
}
</style>
</head>
<body>
<!-- Testing hard coded div works -->
<div class='box'>
<b>fdhfg</b>
</div>
<!-- div through loops not works -->
<div ng-app="myApp" ng-controller="myCtrl">
<div class='box' ng-repeat="product in Products">
<b>fdhfg</b>
</div>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.Products = [
{
"ProductID": "12",
"ProductName": "GreenDetergentBar",
"ProductImagePath": "/images/12.png",
"SubCategoryID": "1",
"SubCategoryName": "DetergentBar",
"BrandID": "1",
"BrandName": "Wheel",
"Variants": [
{
"VariantID": "1",
"VariantName": "500GM",
"VariantImagePath": "/images/12_1.png",
"MRP": "20.00",
"SellPrice": "19.50"
},
{
"VariantID": "2",
"VariantName": "1KG",
"VariantImagePath": "/images/12_2.png",
"MRP": "40.00",
"SellPrice": "38.00"
}
]
},
{
"ProductID": "13",
"ProductName": "AmlaHairOil",
"ProductImagePath": "/images/13.png",
"SubCategoryID": "2",
"SubCategoryName": "HairOil",
"BrandID": "2",
"BrandName": "Dabur",
"Variants": [
{
"VariantID": "3",
"VariantName": "100ML",
"VariantImagePath": "/images/13_3.png",
"MRP": "30.00",
"SellPrice": "29.50"
},
{
"VariantID": "4",
"VariantName": "200ML",
"VariantImagePath": "/images/13_4.png",
"MRP": "60.00",
"SellPrice": "58.00"
}
]
}
];
alert ($scope.Products);
});
</script>
</body>
</html>
有人能帮我解决这个问题吗?
您错过了在ng-app
中定义应用程序名称。
但在你的js中,你提到了:
var app = angular.module('myApp', []);
所以在你的HTML:中是正确的
ng-app="myApp"
哎呀,您已经定义了两次ng-app
。这就是它不能正常工作的原因。必须只有一个ng-app
。
相关文章:
- 另一个ajax调用中的Jquery ajax调用在for循环中没有按预期工作
- AngularJS循环不工作
- For循环在Javascript函数中无法正常工作
- for循环在node.js中的工作方式
- 循环内部的递归函数未按预期工作
- mongoose.js Model.remove在循环中只能工作一次
- JavaScript while循环没有'不能在有条件的情况下工作
- 当if条件被添加到循环中时,Javascript函数将停止工作
- 让循环在我的脚本中工作
- 循环不'不能在“onreadystatechange”中工作
- 如何使此循环工作?它's返回未定义的语言js
- 为什么javascript setTimeout()不能在循环中工作
- jAlert在循环中无法正常工作
- css转换在for循环javascript中无法正常工作
- for循环,if else不工作Javascript
- CSS-转换在JavaScript for循环中不能正常工作
- 从数组中随机选择,但在for循环中选择是不可能的;没有按预期工作
- JavaScript:For循环无法正常工作
- For循环未按预期工作(使用jQuery)
- 为什么我的Javascript Chrome扩展代码不工作?(循环检查按钮)