答案 0 :(得分:0)
好的,我想我知道你在找什么。
我创建了一个新的演示小提琴,因为你的代码难以阅读。
只需使用ng-repeat
循环播放您的论坛列表,然后添加ng-click
即可选择论坛。
请查看下面的演示或此fiddle。
angular.module('demoApp', [])
.controller('mainController', MainController);
function MainController($scope) {
var vm = this,
defaultEntries = [{
id: 0,
name: 'group1'
},{
id: 1,
name: 'group2'
}];
angular.extend(vm, {
groups: defaultEntries,
selectedGroup: defaultEntries[0],
addGroup: function() {
var newGroupName = prompt('enter group name'),
newItem = {id: vm.groups.length+1, name: newGroupName}
vm.groups.push(newItem);
vm.selectedGroup = newItem; // select new item
}
});
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="demoApp" ng-controller="mainController as ctrl">
<button ng-click="ctrl.addGroup()">
Add Group
</button>
<select ng-model="ctrl.selectedGroup" ng-options="group as group.name for group in ctrl.groups"></select>
group selected: {{ctrl.selectedGroup}}
<h1>
Group list
</h1>
<ul>
<li ng-repeat="group in ctrl.groups"><a href="#" ng-click="ctrl.selectedGroup = group">{{group.name}}</a></li>
</ul>
</div>