Basically i got an AngularJS directive with a button and a selectable list (jquery-UI).
The button is disabled with ng-disabled="disabledButton".
disabledButton is a variable in the controller $scope.disabledButton = true;
Now, in the directive, after i click on an element in the list, i want to set the disabledButton to false so the button will be activated.
Here's my HTML code:
<div class="modal-wrapper">
<div panels test-data="testData" disable-button='disableButton'></div>
<div class="bottom-buttons">
<button ng-disabled="disableButton" class="btn btn-primary btn-wizard" ng-click="alertSelected()">NEXT</button>
</div>
</div>
And my directive's code:
portfolioApp.directive('panels', function($timeout) {
return {
restrict: 'A',
replace: true,
templateUrl: 'templates/paneltemplate.htm',
scope: {
testData: "=",
disableButton: "@"
//selectedList: "@"
},
controller: function($scope) {
$scope.selectedList = [];
$scope.clearList = function() {
$scope.selectedList.length = 0;
}
},
link: function($scope, element, attrs, panelsController) {
$timeout(function() {
if(!$scope.$$phase) {
$('#selectable').selectable( {
filter: "li",
selected: function(event, elem) {
// this will return the first of the selecteds
var selecteds = $('#selectable').find('.ui-selected').children().eq(0).children().text();
$scope.selectedList.push(selecteds);
console.log($scope.selectedList);
$scope.$apply(function() {
$scope.disableButton = false;
});
console.log('look im being selected!')
},
unselected: function(event, ui) {
$scope.clearList();
}
});
$scope.$apply();
}
},0);
}
}
})