call scope function from outside

How get access to scope outside of controller

by Slava Nikishkin

HTML

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<div ng-app="myApp">
  <div ng-controller="MyController" id="ctrl1">
  <button id="btn1">click me</button>
  {{txt}}
  </div>
</div>

JavaScript

angular.module("myApp", [])
        .controller("MyController", function ($scope) {
        
          $scope.alert = function() {
            $scope.txt = "inner function has been called";
            // for refresh view
            $scope.$apply();
          };
          
        })
      ;
      
setTimeout(function () {

document.getElementById("btn1").addEventListener("click"
  , function () {
    angular.element(ctrl1).scope().alert();
    //angular.element(ctrl1).scope().alert();
  })
  
  }, 1000);