Abaij Abaij - 5 months ago 17
AngularJS Question

How to use if statement conditional in angular js

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>

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.


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>