상점이 현재 시간을 기준으로 열려 있거나 닫혔는지 여부를 표시하려고합니다. 여기 코드가 있습니다. 뷰각도 js의 조건문을 사용하는 방법
<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>
문제에서 제어기
$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
에서
, 결과는 첫 번째 조건 item.open_hour != '00:00:00'
나머지는 거역된다 충족된다는 것이다. 따라서 open_hour 및 close_hour에 관계없이 '00 : 00 : 00 '이 아닌 open_hour가있는 모든 데이터가 열립니다.
나는 angularjs를 처음 사용하고 이런 식으로하는 법을 모릅니다. 제발 어떤 도움을 주시면 감사하겠습니다.
'<스팬 = "은 {{item.open_hour = 00가! : 00 : 00 '&& item.open_hour <='CURRENT_TIME NG-경우 '&& item.close_hour> = CURRENT_TIME}}"> 우리는' 다시 열어'이 (가) –
@HardikVaghani로 바꿔주세요. 답이 잘못되었습니다. item.open_hour <= 'current_time'' → current_time 범위가 아닌 문자열. 문자열이 아닙니다. – gianlucatursi
@HardikVaghani 그 작품! 그러나 나는 그것이 current_time에서 따옴표없이 있어야한다고 생각합니다. 어쨌든 고마워. – Abaij