Skip to content

Instantly share code, notes, and snippets.

@abusedmedia
Created October 4, 2013 09:39
Show Gist options
  • Save abusedmedia/6823476 to your computer and use it in GitHub Desktop.
Save abusedmedia/6823476 to your computer and use it in GitHub Desktop.
Get the reference Scope of a selected element
// assuming the following angular code
function Ctrl($scope){
$scope.thevar = 'SOME';
$scope.something = function(){
$scope.thevar = 'CHANGED';
}
}
// the html element:
/* <p id="el">{{thevar}}</p> */
// get the reference
var cscope = angular.element( $('#el') ).scope()
// call a scope method
cscope.$apply(function(){
cf.something();
});
// change a variable value
cscope.$apply(function(){
cscope.thevar = 'AGAIN';
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment