我正在尝试思考angular,但我不确定如何在jQuery中为加载元素赋值。
我有以下标签,所有这些标签在点击后都会被“选中”。如何在加载时选择一个选项卡,以便在没有用户做任何事情的情况下“选择”一个选项卡?
<ul class="nav nav-tabs">
<li ng-class="{active: selected == 1}">
<a href="" ng-click="selected=1">Overview</a>
</li>
<li ng-class="{active: selected == 2}">
<a href="" ng-click="selected=2">My Properties</a>
</li>
<li ng-class="{active: selected == 3}">
<a href="" ng-click="selected=3">Potential Properties</a>
</li>
</ul>
<div ng-if="selected == 1">
<div ng-include=" 'views/dash/_overview.html' "></div>
</div>
<div ng-if="selected == 2">
<div ng-include=" 'views/dash/_myproperties.html' "></div>
</div>
<div ng-if="selected == 3">
<div ng-include=" 'views/dash/_buyproperties.html' "></div>
</div>
答案 0 :(得分:1)
在你的控制器开始时
$scope.selected = 1;
但你可能应该把它放在一个对象中以保持$ scope clean
$scope.data = {
selectedTab:1
};
和
<li ng-class="{active: data.selectedTab == 1}">
<div ng-if="data.selectedTab == 1">
等