2016-12-30 27 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

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