我試圖使用選項選擇值動態創建div
,但ng-repeat
無法正常工作。讓我知道我在這裏做錯了什麼。在AngularJS的選項選項上動態創建div
以下是我的HTML代碼 -
<!doctype html>
<html lang="en" ng-app="myApp">
<head>
<meta charset="utf-8" />
<title>Select Example - AngularJS</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.10/angular.min.js"></script>
<script src="script.js"></script>
</head>
<body ng-controller="myCtrl">
<select id="shiftnumbers"
ng-model="event.shiftnumber"
ng-options="timeslot.value as timeslot.name for timeslot in shiftnumbers"
ng-init="event.shiftnumber = shiftnumbers[0].value"
class="btn">
</select>
<div ng-repeat="event.shiftnumber">{{event.shiftnumber}}</div>
</body>
</html>
以下是我Script
-
var myApp = angular.module("myApp", []);
myApp.controller("myCtrl", function($scope){
$scope.shiftnumbers = [];
for(var i=0; i< 23; i++) {
$scope.shiftnumbers.push({name: i, value: i});
}
});
PLNKR LINK - http://plnkr.co/edit/UruYYbXrTgxqXadIb8A3?p=preview
看看這個問題[AngularJS For循環用數字和範圍(HTTP://計算器。 com/questions/11873570/angularjs-for-loop-with-numbers-ranges) – 2014-08-27 09:33:30
@Gru ffBunny Thx的鏈接..我在這裏應用範圍方法..但感覺什麼satpal建議適合我的情況太緊密:) – Trialcoder 2014-08-27 09:48:47