angular isolated scope in directive refers to parent scope

by davekr

HTML

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular.js"></script>
<div ng-app="app">
    <dir1></dir1>
</div>

JavaScript

angular.module('app', [])
.run(function ($rootScope) {
    $rootScope.val1 = '11';
    $rootScope.val2 = '22';
})
.directive('dir1', function () {
    return {
        restrict: 'E',
        scope: {},
        template: '<a onclick="angular.element(this).scope().test()">template</a>',
        link: function (scope, element, attrs, ctrl, transclude) {
            scope.test = function(){console.log('test');}
        }
    };
});