我看到类似的问题,但我不知道如何处理angularjs。 这段代码返回一个数组,我希望在特定的预约时间内制作超链接标记。
html代码:<a> </a>
css代码:
a:link, a:visited {
background-color: white;
color: black;
padding: 9px 25px;
text-align: center;
text-decoration: none;
display: inline-block;
line-height: 0em;
}
a:hover, a:active {
background-color: #52D017;
}`
脚本:
var d = 12;
var n = 0,
min = 20,
periods = [" AM", " PM"],
times = [],
hours = [ 9, 10, 11,12, 5,6,7,8];
for (var i = 0; i < hours.length; i++) {
times.push(hours[i] + ":" + n + n + periods[0]);
while (n < 60 - min) {
times.push(hours[i] + ":" + ((n += 20) < 10 ? "O" + n : n) + periods[0])
}
n = 0;
}
times = times.concat(times.slice(0).map(function(time) {
return time.replace(periods[0], periods[1])
}));
console.log(times);
document.querySelector("a").textContent += times.join()
请帮我改变angularjs中的代码并使用ng-reapeat并点击特定时间。
答案 0 :(得分:4)
使用ng-repeat
指令:
<div ng-repeat="v in times">
<pre>{{v|json}}</pre> <!-- for demo only-->
</div>
固定代码(已将time
替换为$scope.time
):
var app = angular.module('myModule', []);
app.controller('fessCntrl', function($scope, $timeout) {
var d = 12,
n = 0,
min = 20,
periods = [" AM", " PM"],
hours = [9, 10, 11, 12, 5, 6, 7, 8];
$scope.times = [];
for (var i = 0; i < hours.length; i++) {
$scope.times.push(hours[i] + ":" + n + n + periods[0]);
while (n < 60 - min) {
$scope.times.push(hours[i] + ":" + ((n += 20) < 10 ? "O" + n : n) + periods[0])
}
n = 0;
}
$scope.times = $scope.times.concat($scope.times.slice(0).map(function(time) {
return time.replace(periods[0], periods[1])
}));
});