JavaScript AngularJS - Ng-class choose wrong class angularjs choose class

I've a problem with my App, normally , ng-class displays a different background according to the time indicated in the database.

It works fine on other views ( Home, and when creating ), but in the ad page, it defaults to the class "night" . I was fine all night searching , but I have not been able to find where the problem is , this is what I have in console:

<div class="item night" ng-class="{"sunset":true}"></div>

And in other view (When it's work) :

<div class="item sunset" ng-class="{"sunset":true}"></div>

I'll precise : All services in all views are the same. Do you have an idea of ​​where it may come ?

HTML :

<div class="list">
  <div class="item" ng-class="{{ event.starthourid | setImageClass}}">
  <h2 class="text stable animated tada" id="eventtitle"> {{ event.nameid }} </h2> 
</div> 

Service.JS :

myApp.filter("setImageClass", function(){
  return function(input) {
    var h = new Date(input).getHours();
    if (h>=6 && h<11) {
      return {sunrise: true};
    } else if (h>=11 && h<18) {
      return {day: true};
    } else if (h>=18 && h<22) {
      return {sunset: true};
    } else {
      return {night: true};
    }
  };
});

Thank you all for reading! (I can add code if you want)

Answer:1
ng-class="{"sunset":true}"

should be

ng-class="{sunset: true}"

or

ng-class="{'sunset': true}"
Answer:2

Remove the curly braces {{}} around ng-class expression.

Following are valid expressions for ng-class attribute,

<div ng-class="className">

<div ng-class="getClassNameFunc()">

<div ng-class="{className: booleanValue}">

Below is a sample snippet.

var app = angular.module("myapp", []);

app.controller("testCntrl", function($scope) {
  $scope.isNight = false;
  $scope.checkNight = function() {
    $scope.isNight = !$scope.isNight;
  }

  $scope.getIsNight = function() {
    return $scope.isNight;
  }
})
#div1 {
  width: 100px;
  height: 100px
}
.night {
  background-color: #000;
  color: #fff;
}
.day {
  background-color: #fff;
  color: #000;
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myapp">
  <div ng-controller="testCntrl">
    <div id="div1" ng-class="{night: getIsNight()}">
      <span ng-show="!isNight">Its Day </span>
      <span ng-show="isNight">Its Night </span>
    </div>
    <button ng-click="checkNight()">{{isNight ? "Day": "Night" }}</button>
  </div>
</div>
Answer:3

Let's say I have this string: <i id="1"></i><i id="2"></i><i id="3"></i> and this object: { "1": "Red", "2": "Green", "3": "Blue" } Then I want to obtain ...

Let's say I have this string: <i id="1"></i><i id="2"></i><i id="3"></i> and this object: { "1": "Red", "2": "Green", "3": "Blue" } Then I want to obtain ...

  1. string replace with regex
  2. string replace with regex python
  3. string replace with empty
  4. string replace with regex java
  5. string replace with regex javascript
  6. string replace with dictionary python
  7. string replace with python
  8. string replace with regex c#
  9. string replace with regex js
  10. string replace with empty char java
  11. string replace with empty char c#
  12. string replace with variable python
  13. string replace with multiple values
  14. string replace with space
  15. string replace with index in java
  16. string replace with java
  17. string replace with index
  18. string replace with variable javascript
  19. string replace with null java
  20. string replace with space java

I am trying to toggle plus and minus span and also toggle the answer div all at once and its not working out. I built the html so the question div has two childrens: div icons with two children of ...

I am trying to toggle plus and minus span and also toggle the answer div all at once and its not working out. I built the html so the question div has two childrens: div icons with two children of ...

  1. jquery toggle class onclick
  2. jquery toggle class animation
  3. jquery toggleclass not working
  4. jquery toggle class on hover
  5. jquery toggle class multiple
  6. jquery toggle class based on boolean
  7. jquery toggle class on button click
  8. jquery toggleclass delay
  9. jquery toggle class hide show
  10. jquery toggle class codepen
  11. jquery toggle class on scroll
  12. jquery toggle class condition
  13. jquery toggle class function
  14. jquery toggle class click
  15. jquery toggle class callback
  16. jquery toggle class by id
  17. jquery toggleclass off
  18. jquery toggle class visibility
  19. jquery toggle class this
  20. jquery toggle class on focus

I am a beginner with typescript and playing with it on their Playground site. I have the following code: class Queue<T> { private data = []; push = (item: T) => this.data.push(item)...

I am a beginner with typescript and playing with it on their Playground site. I have the following code: class Queue<T> { private data = []; push = (item: T) => this.data.push(item)...

  1. typescript doesn't compile
  2. typescript doesn't compile on save
  3. typescript doesn't work
  4. typescript doesn't understand
  5. typescript does not like
  6. typescript import doesn't work
  7. typescript instanceof doesn't work
  8. typescript exclude doesn't work
  9. typescript concat doesn't work
  10. typescript await doesn't work
  11. typescript filter doesn't work
  12. typescript await doesn't wait
  13. typescript foreach doesn't work
  14. typescript getter doesn't work
  15. typescript regex doesn't work
  16. typescript settimeout doesn't work
  17. typescript object doesn't support this action
  18. typescript includes does not work
  19. typescript typings doesn't work
  20. typescript property does not exists

I've been struggling with sending a POST request and fetching data back using Node.js I've been trialing like this var querystring = require('querystring'); var http = require('http'); var postData ...

I've been struggling with sending a POST request and fetching data back using Node.js I've been trialing like this var querystring = require('querystring'); var http = require('http'); var postData ...

  1. send post request javascript
  2. send post request python
  3. send post request curl
  4. send post request from chrome
  5. send post request online
  6. send post request java
  7. send post request postman
  8. send post request c#
  9. send post request powershell
  10. send post request php
  11. send post request from command line
  12. send post request golang
  13. send post request react
  14. send post request js
  15. send post request from terminal
  16. send post request html
  17. send post request in url
  18. send post request node
  19. send post request with parameters
  20. send post request to localhost