1

i see the similar question but i didn't know how to deal this in angularjs. This code return me a array and i want to make hyperlink tag in particular time for book appointment.

html code: <a> </a>

css code:

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;
}`

script:

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()

please help me out to change this code in angularjs and using ng-reapeat and click on particular time.

1 Answer 1

4

Use ng-repeat directive as:

<div ng-repeat="v in times">
  <pre>{{v|json}}</pre> <!-- for demo only-->
</div>

Demo


Fixed code (replaced time with $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])
  }));
});
Sign up to request clarification or add additional context in comments.

4 Comments

but when i run this code on my controller nothing will happen jsfiddle.net/y7hyheaa/2
confused with controller how to deal
@AshishGoyal well, its a Angular base, suggest you to start from tutorial mate :) . anyways I answered on your question
it always showing time in both am and pm means as above code i mention showing and categorize am and pm i.e 9,10,11 showing AM & 12,5,6,7,8 showing PM but you mention the code is not categorize .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.