2013-11-21 113 views
3

我試圖做一個切換角度的東西,我不明白爲什麼它不起作用。在點擊角度設置範圍值?

我看到,當我點擊a標籤時,應該顯示較低的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> 

回答

3

是的,這工作。我已經把一個快速plunkr來測試它:

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="[email protected]" 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> 
+0

嗯,這很煩人...謝謝。 – Himmators

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>