2017-11-22 1 views
1

wenn ich Wert in HTML binden möchte, die wahr oder falsch ist. Wie kann ich diesen Wert anzeigen?Wie kann ich Wert in Element binden, wenn ich richtig oder falsch bin?

Code:

<li ng-if="display"><a ng-click="logout();" ><span class="icon mail"> 
</span>Logout</a></li> 
<li ng-if="!display"><a href="#/login"><span class="icon mail"> 
</span>Login/Signup</a></li> 
<li>{{$scope.display}}</li> // i want to print it here. 

Anzeigewert wahr oder falsch ist, wie kann ich es drucken? ist es möglich?

+0

nur entfernen Sie die '$ scope' –

Antwort

0

Sie müssen $ scope nicht hinzufügen, während Sie in HTML drucken. Sie können einfach so binden.

<input type="text" ng-bind="display"> 
<li>{{display}}</li> 
+0

Dank es funktioniert hilft. –

0

versuchen, dies kann man es

<!DOCTYPE html> 
 
<html> 
 
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script> 
 
<body ng-app=""> 
 

 
Keep HTML: 
 
<input type="checkbox" ng-model="myVar" ng-init="myVar = true"> 
 

 
<div ng-if="myVar"> 
 
<h1>Welcome</h1> 
 
<p>Welcome to my home.</p> 
 
<hr> 
 
</div> 
 
<p style="font-size:40px">{{myVar}}</p> 
 

 
<p>The DIV element will be removed when the checkbox is not checked.</p> 
 
<p>The DIV element will return, if you check the checkbox.</p> 
 

 
</body> 
 
</html>

Verwandte Themen