我正试图以角度进行切换 - 我无法理解为什么它不起作用。
我说,当我点击a-tag时,应显示下面的div。
<div>
<a href="#" ng-click='member = mathieu' class="mathieu">Lorem<br />Ipsum<span>Click for more</span></a>
</div>
<div ng-switch="member">
<div ng-switch-when="mathieu">
<h3>Lorem ipsum</h3>
</div>
</div>
答案 0 :(得分:3)
是的,这很有效。我已经组装了一个快速的傻瓜来测试它:
http://plnkr.co/edit/9JqxRNC9X5U2bJrkbxZ9?p=preview
<!DOCTYPE html>
<html ng-app="plunker">
<head>
<meta charset="utf-8" />
<title>AngularJS Plunker</title>
<script data-require="angular.js@1.2.x" src="http://code.angularjs.org/1.2.1/angular.js" data-semver="1.2.1"></script>
<script src="app.js"></script>
</head>
<body>
<a href="#" ng-click="member = 'mathieu'" class="mathieu">Lorem Ipsum <span>Click for more</span>
</a>
<br />
<a href="#" ng-click="member = ''" class="mathieu">
<span>Click to reset</span>
</a>
</div>
<div ng-switch="member">
<div ng-switch-when="mathieu">
<h3>Lorem ipsum</h3>
</div>
</div>
</body>
</html>
答案 1 :(得分:2)
mathieu
需要是一个字符串值。它本身将解析为undefined
。
我想你正在寻找这样的东西:
<div>
<a href="#" ng-click="member = 'mathieu'" class="mathieu">Lorem<br />Ipsum<span>Click for more</span></a>
</div>
<div ng-switch="member">
<div ng-switch-when="mathieu">
<h3>Lorem ipsum</h3>
</div>
</div>