我想切换我将在用户和帖子之间显示的html +数据..它有点像Instagram帖子/用户的功能
<div ng-controller="MainCtrl">
<div class="button-bar">
<a class="button" ng-class="{'button-positive': isActive('posts')}" ng-click="setActive('posts')">Posts</a>
<a class="button" ng-class="{'button-positive': isActive('users')}" ng-click="setActive('users')">User</a>
</div>
</div>
<div class="users">
<ul>
<li ng-repeat="user in users" href="#/tab/user/{{user.id}}">
<img ng-src="{{user.face}}">
<h2>{{user.name}}</h2>
</li>
</ul>
</div>
<div class="posts">
<ul>
<li ng-repeat="post in posts" href="#/tab/post/{{post.id}}">
<h2>{{post.name}}</h2>
<p>{{post.description}}</p>
</li>
</ul>
</div>
答案 0 :(得分:0)
您可以使用此逻辑
分解为分
initialtoggle
设置初始值ng-click
点检查更改initialtoggle
。initialtoggle
与user
或posts
值进行比较
申请合适的班级。显示ng-if
comapiring值为的相应div
initialtoggle
。
<div ng-controller="MainCtrl" ng-init="initialtoggle='user'">
<div class="button-bar">
<a class="button"
ng-class="{'button-positive': initialtoggle == 'posts'}"
ng-click="initialtoggle='posts'">Posts</a>
<a class="button" ng-class="{'button-positive': initialtoggle == 'user'}"
ng-click="initialtoggle='user'">User</a>
</div>
</div>
<div class="users" ng-if="initialtoggle=='user'">
<ul>
<li ng-repeat="user in users" href="#/tab/user/{{user.id}}">
<img ng-src="{{user.face}}">
<h2>{{user.name}}</h2>
</li>
</ul>
</div>
<div class="posts" ng-if="initialtoggle=='user'">
<ul>
<li ng-repeat="post in posts" href="#/tab/post/{{post.id}}">
<h2>{{post.name}}</h2>
<p>{{post.description}}</p>
</li>
</ul>
</div>