如果我想在Html中绑定值为true或false。如何显示此值?
代码:
<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.
显示值是true还是false我该如何打印?有可能吗?
答案 0 :(得分:1)
在html中打印时,您不需要添加$ scope。 你可以像这样绑定。
<input type="text" ng-bind="display">
<li>{{display}}</li>
答案 1 :(得分:0)
尝试这个可能有帮助
<!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>