1

I want to show a status whether the shop is open or close based on current time. So here is the code.

In controller

$http.get(httpUrl + 'shops/get_shops')
.then(function (returns) {
   $scope.shops = returns.data;
});
var now = new Date();
$scope.current_time = now.getHours() + ':' + now.getMinutes() + ':00';// to get hh:mm:ss format

In the view

<div ng-repeat="item in shops">
   <span ng-if="item.open_hour != '00:00:00' && item.open_hour <= '{{current_time}}' && item.close_hour >= {{current_time}}">We're open</span>
</div>

The problem is that the result is only meet the first condition item.open_hour != '00:00:00' and the rest are disobeyed. So all the data which have open_hour not '00:00:00' will be open regardless the open_hour and close_hour.

I'm new to angularjs and don't know how to do thing like this. Please any help will be appreciated.

3
  • <span ng-if="{{item.open_hour != '00:00:00' && item.open_hour <= 'current_time' && item.close_hour >= current_time}}">We're open</span> change to this Commented Aug 24, 2016 at 8:59
  • @HardikVaghani your answer it's wrong. item.open_hour <= 'current_time' → current_time it's a scope var not a string. Commented Aug 24, 2016 at 9:03
  • @HardikVaghani that's work!! but I think it should be without quote in current_time. thanks anyway Commented Aug 24, 2016 at 9:06

1 Answer 1

3

When you are in ng-if you don't need {{}} for getting a scope var.

<span ng-if="item.open_hour != '00:00:00' && item.open_hour <= current_time && item.close_hour >= current_time">We're open</span>
Sign up to request clarification or add additional context in comments.

Comments

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.