I think I need a break and cup of tea on this one.
<tr ng-repeat="participant in globalData" ng-controller="GlobalDataRowController" ng-class="rowStatus">
<td>
<li class="dropdown">
<a class="dropdown-toggle">
Click me for a dropdown, yo!
</a>
<ul class="dropdown-menu">
<li ng-repeat="choice in participant.SourceDescriptions">
<a>{{choice}}</a>
</li>
</ul>
</li>
....
I have this code. When the this snippet is placed outside the repeat scope it works fine. But inside the repeat nothing happens when I click.
I'm attempting to use angular-ui but I'd rather not have it just for this job. And I don't think I'm looking at the problem correctly anyway.
I've been looking back over previous questions and thought I'd wrap this one up.
I took the approach of using a directive here. It doesn't look perfect but it's doing the job for now. So in the view...
<tr ng-repeat="participant in globalData" ng-controller="GlobalDataRowController" ng-class="rowStatus">
<td>
<input input-data-list-dropdown id="xx" input-class="input-xxlarge" ng-model="participant.DisplayName" options="participant.SourceDescriptions">
...
</td>
</tr>
And the directive...
.directive('inputDataListDropdown', function () {
return {
replace: true,
scope: { options: '=', ngModel: '=', inputClass: '=', id: '=' },
template: '<span class="dropdown">' +
'<a class="dropdown-toggle">'+
'<input type="text" class="inputDataListDropdown" ng-transclude ng-model="ngModel">' +
'</a>'+
'<ul class="dropdown-menu no-bullets" ng-show="options && options.length > 0">' +
'<li ng-repeat="option in options">' +
'<a ng-click="$parent.ngModel=option">{{option}}</a>' +
'</li>'+
'</ul>'+
'</span>',
transclude: 'element',
link: function ($scope, element, attrs) {
$("#" + attrs.id + " .inputDataListDropdown").addClass(attrs.inputClass);
}
};
});
<!-- a function -->
$scope.drop_down1 = function () {
$scope.status = {
isopen: false
};
$scope.toggled = function(open) {
$log.log('Dropdown is now: ', open);
};
$scope.toggleDropdown = function($event) {
$event.preventDefault();
$event.stopPropagation();
$scope.status.isopen = !$scope.status.isopen;
};
};
<!--create view and use ng-include-->
<div class="btn-group" dropdown is-open="status.isopen">
<button type="button" class="btn btn-primary dropdown-toggle" ng-click="drop_down1()" dropdown-toggle ng-disabled="disabled">
Button dropdown <span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
<li class="divider"></li>
<li><a href="#">Separated link</a></li>
</ul>
</div>
<!-- ng-repeat example -->
<table class="table table-hover">
<thead>
<tr>
<th>id</th>
<th>vm_name</th>
<th>date</th>
<th>restore_type</th>
<th>state</th>
<th>Button</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="x in data | filter:searchFilter | orderBy: 'id' :true">
<td>{{x.id}}</td>
<td>{{x.vm_name}}</td>
<td>{{x.date}}</td>
<td>{{x.restore_type}}</td>
<td>{{x.state}}</td>
<td>
<div id="ctrl_10_butt" ng-include="'view/view_drop1.html'"></div>
</td>
</tr>
</tbody>
</table>