<script>
var app = angular.module("myapp", []);
app.controller('test',function($scope){
$scope.my="hi";
$scope.myimag=["Feature-Category1.png","Feature-Category2.png","Feature-Category3.png","Feature-Category1.png","Feature-Category1.png"];
});
</script>
<body ng-app="myapp">
<div ng-controller="test">
<div class="col-md-3 col-sm-3 col-xs-3" ng-repeat="x in myimag">
<a href="#"><img alt="" ng-src="{{x}}"></a>
</div>
</div>
</body>
我想重复myimg中的项目,但是它不能正常运行
答案 0 :(得分:0)
您缺少模块,控制器并再次使用 $scope
变量而不是var,
$scope.myimg=["img.png","img1.png","img2.png"];
<强>样本强>
var testApp= angular.module('test',[])
angular.module('test').controller('testCtrl',function($scope){
$scope.myimg=["altair7.jpg","altair6.jpg"];
})
&#13;
<!doctype html>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.min.js"></script>
<script src="app.js"></script>
<script src="testCtrl.js"></script>
</head>
<body ng-app="test">
<div ng-controller="testCtrl">
<div class="col-md-2" ng-repeat="x in myimg ">
<a href="#"><img ng-src="{{x}}"></a>
</div>
</div>
</body>
</html>
&#13;
答案 1 :(得分:0)
代码存在三个问题:
更新您的代码,如下所示:
angular.module('myApp', [])
.controller('myController', function TodoCtrl($scope) {
$scope.myimg=["img.png","img1.png","img2.png"];
});
<强> HTML 强>
<div ng-app="myApp" ng-controller="myController">
<div class="col-md-2" ng-repeat="x in myimg ">
<a href="#"><img ng-src="{{x}}"></a>
</div>
</div>