【发布时间】:2015-04-23 14:20:44
【问题描述】:
所以我只是从 Angular JS 开始,在处理数组时对 ng-repeat 有点困惑。下面的代码不能按原样工作......但是当我将 dayNames 更改为一个对象并为其提供键值对时,它很好。
var myApp = angular.module('exampleApp', []);
myApp.controller("dayCtrl",function($scope){
$scope.dayNames = ["sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "sunday", "monday", "tuesday", "wednesday", "thursday", "friday"];
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<!DOCTYPE html>
<html ng-app="exampleApp">
<head>
<script src="angular.js"></script>
<script src="controller.js"></script>
</head>
<body ng-controller="dayCtrl">
<h2>Hello, these are the days of the week</h2>
<ul>
<li ng-repeat="day in dayNames">{{day}}</li>
</ul>
</body>
</html>
【问题讨论】:
标签: arrays angularjs ng-repeat