Access angular scope outside

by Florian Bar

HTML

<div ng-app>
    <div id="outer" ng-controller="MsgCtrl">
        You are {{msg}}
    </div>
    <div onclick="change()">click me</div>
</div>

JavaScript

function MsgCtrl($scope) 
{
    $scope.msg = "great";
}

function accessScope(node, func) {
	var scope = angular.element(document.querySelector(node)).scope();
    scope.$apply(func);
}

function change()
{
    alert("a");
    accessScope('#outer', function (scope) {
        scope.msg = 'Superhero';
    });
}