2016-06-03 16 views
-1

ich unter HTML-ng-Show bin mit:Angular ng-Show funktioniert nicht wie erwartet

<span ng-show="show_notif_count=1" class="m-alert" id="notif_count">{{notif_count}}</span> 

js Code:

$scope.show_notif_count = 0; 
    $http.get('count/',{headers:{'Content-Type':'application/x-www-form-urlencoded'}}) 
    .success(function(response) 
    { 
     console.log($scope.show_notif_count); 
     if(response>2) 
     { 
      $scope.show_notif_count = 1; 
      console.log(response); 
      $scope.notif_count = response; 
     } 

    }); 

Das Problem ist ng-Show verbirgt nie die Spannweite und es wird immer angezeigt. Ich habe versucht, "==" anstelle von "=" und auch andere Werte für "show_notif_count" zu verwenden, aber entweder erscheint es immer oder versteckt sich immer. Was könnte mit dem obigen Code falsch sein?

+0

Was erhalten Sie als Antwort? – Rakeschand

+0

Ich bekomme 3, 4 oder etwas Größeres als 2. Mein Freund wird zufrieden, wenn ich es durch Alert oder console.log verifiziere. – Simer

+0

Ich bekomme Integer-Wert als Antwort. – Simer

Antwort

3

show_notif_count=1 ist der Wert für die Variable, die nicht verglichen werden soll.

Update:

<span ng-show="show_notif_count=1" class="m-alert" id="notif_count">{{notif_count}}</span> 

An:

<span ng-show="show_notif_count === 1" class="m-alert" id="notif_count">{{notif_count}}</span> 

Hinweis: Es wird ausgeblendet, wenn response <= 2, bitte noch einmal das Verhalten überprüfen.

+0

Ich habe "=" auf "===" aktualisiert, jetzt bleibt es immer versteckt. Ich sehe folgenden HTML in Firebug " 2" in deaktivierter Form. Ich kümmere mich um alle Prüfungen, indem ich Dinge im Konsolenprotokoll drucke. – Simer

+0

'Antwort <= 2' =>' notif_count = Antwort' => Es wird – WorkWe

+0

verstecken meine Bedingungen funktionieren gut und wenn ich log "show_notif_count" es gibt 1. Dann, warum span nicht angezeigt wird? – Simer

Verwandte Themen