Jade If Statement does not work with variable

I am trying to compare the value of a variable with a constant string, and I cannot get the if statement to work correctly. I am using Angular.js with Jade.

Here is my code.

ol
  li(ng-repeat = "notification in notificationData")
    - var typeOfNotification = '{{ notification.typeOfNotification }}'
    p #{ typeOfNotification }
    -if (typeOfNotification == 'like')
      p LIKED
    -else
      p ELSE

It gives a way out

like

ELSE

follow

ELSE

like

ELSE

like

ELSE

follow

ELSE

The if statement is never considered true, although the p #{ typeOfNotification }line above shows that for some cases the variable contains a value like. How do I change the Jade code so that it works correctly?

Thank.

+4
source share
2 answers

The problem here is: the Jade evaluation will be completed before Angular is initialized.
Therefore you cannot mix it!

Jade ? JavaScript ?

, Angular, DOM Jade , , Jade.

, , Jade Angular . Angular, ng-call - pewudo Angular, , node:

script.
  var getNotificationType = function(notification) {
    return notification.typeOfNotification
  }
  var typeIsLike = function(n) {
    var type = getNotificationType(n);
    if (type === 'like') {
      return 'LIKED';
    }
    return 'ELSE';
  }
  var foo = "bar";


ol
  li(ng-repeat = "notification in notificationData")
  p(ng-call = "getNotificationType(notification)")
  p(ng-call = "typeIsLike(notification)")

BTW: p= typeOfNotification p #{ typeOfNotification }
( ;)

+3

angular jade , , angular ng-if .

ol
  li(ng-repeat = "notification in notificationData")
    p(ng-if= "notification.typeOfNotification == 'like'") LIKED 
    p(ng-if= "notification.typeOfNotification != 'like'") ELSE
0

Source: https://habr.com/ru/post/1531668/


All Articles