Created
October 4, 2013 09:39
-
-
Save abusedmedia/6823476 to your computer and use it in GitHub Desktop.
Get the reference Scope of a selected element
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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