Skip to content

Instantly share code, notes, and snippets.

@anonymoussc
Created October 27, 2015 06:40
Show Gist options
  • Save anonymoussc/34593bb757db7ee8366b to your computer and use it in GitHub Desktop.
Save anonymoussc/34593bb757db7ee8366b to your computer and use it in GitHub Desktop.
Updating the AngularJS scope in Response to the jQuery UI Click
<!DOCTYPE html>
<html ng-app="exampleApp">
<head>
<title>Controllers</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js">
</script>
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/themes/sunny/jquery-ui.min.css">
<script>
$(document).ready(function() {
$('#jqui button').button().click(function(e) {
angular.element(angularRegion).scope().$apply('handleClick()');
});
});
var app = angular.module("exampleApp", [])
.controller("simpleCtrl", function($scope) {
$scope.buttonEnabled = true;
$scope.clickCounter = 0;
$scope.handleClick = function() {
$scope.clickCounter++;
};
$scope.$watch('buttonEnabled', function(newValue) {
$('#jqui button').button({
disabled: !newValue
});
});
});
</script>
</head>
<body>
<div id="angularRegion" class="well" ng-controller="simpleCtrl">
<h4>AngularJS</h4>
<div class="checkbox">
<label>
<input type="checkbox" ng-model="buttonEnabled"> Enable Button
</label>
</div>
Click counter: {{clickCounter}}
</div>
<div id="jqui" class="well">
<h4>jQuery UI</h4>
<button>Click Me!</button>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment