所以我有两个按钮,它们的作用是当单击其中一个按钮时显示它们各自的数据。现在第一次加载页面时显示活动颜色 - AngularJS
<div>
<h1>Ng-show & ng-hide</h1>
<p class="description">Click on the "show"-link to see the content.</p>
<button ng-click="showme=true" ng-class="{activeButton: showme == true}">Show</button>
<button ng-click="showme=false" ng-class="{activeButton: showme == false}">Hide</button>
<div class="wrapper">
<p ng-hide="showme">It will appear here!</p>
<h2 ng-show="showme">This is mah content, yo!</h2>
</div>
</div>
,我加入了NG-类显示一个积极的颜色(说“红”),当按钮被点击,另一个应该回到它的原始颜色(蓝色)。当页面加载时,我看到的第一件事是“它会出现在这里!”的消息。这很好,但代表(“隐藏”)此消息的按钮不具有活动的红色。
当页面首次加载到此按钮时,我如何设置默认的活动颜色?我想保持切换功能,我应该可以点击一个按钮,看到活动的颜色。
您的帮助将不胜感激,提前致谢!
设置的
showme
值作为true
'NG-init'或定义'showme'在控制器... – Rayon页面加载后的第一次,变量'showme'没有任何值,所以它等于'undefined'。通过上面的代码,将'ng-class'的值改为'{activeButton:showme}'和'{activeButton:!showme}'会起作用 –
谢谢你们,这真的有帮助! AngularJS的全新 – medev21