2016-12-30 30 views
-2

我用想div标签重复NG-repat

<script> 
 
\t \t var app = angular.module("myapp", []); 
 
    app.controller('test',function($scope){ 
 
\t \t $scope.my="hi"; 
 
\t $scope.myimag=["Feature-Category1.png","Feature-Category2.png","Feature-Category3.png","Feature-Category1.png","Feature-Category1.png"]; 
 

 
\t \t \t }); 
 
\t \t </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> 
 
\t </div> 
 
    </div> 
 
\t </body> \t \t \t \t \t \t \t \t \t \t

我想重复在myimg的项目,但它不工作就明白为什么

回答

0

你缺少模块,控制器错误,再次使用$scope变量,而不是无功,

$scope.myimg=["img.png","img1.png","img2.png"]; 

DEMO

var testApp= angular.module('test',[]) 
 
angular.module('test').controller('testCtrl',function($scope){ 
 
$scope.myimg=["altair7.jpg","altair6.jpg"]; 
 
})
<!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>

+0

也是错误 –

+0

@banuprak灰检查演示 – Sajeetharan

+0

看到我的代码中的变化,但无法正常工作 –

0

三个问题你的代码:

  1. 您还没有定义的角模块。
  2. 您尚未为该视图定义控制器。
  3. 为了acheive双向数据绑定,您需要使用$范围定义,而不是将其定义为“VAR”

更新你的代码的变量,如下图所示:

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> 
+0

ok发布代码 –

+0

看到我的代码中的更改但不工作 –