Can't open modal onLoad


I am having trouble opening a modal on body load. Here is my code, that I pretty much copied and pasted from here:

.controller('LoginController', function($scope, $ionicModal) {
  $ionicModal.fromTemplateUrl('templates/login.html', {
    scope: $scope,
    animation: 'slide-in-up'
  }).then(function(modal) {
    $scope.modal = modal;
  $scope.openModal = function() {
  $scope.closeModal = function() {
  //Cleanup the modal when we're done with it!
  $scope.$on('$destroy', function() {
  // Execute action on hide modal
  $scope.$on('modal.hidden', function() {
    // Execute action
  // Execute action on remove modal
  $scope.$on('modal.removed', function() {
    // Execute action

<script id="templates/login.html" type="text/ng-template">
    <ion-header-bar class="bar-dark">
      <h1 class="title">Login to</h1>

I am able to open the modal using "ng-click=“openModal()” but I want to instead open it using body onLoad. However, this is not working for me. Yet it works in this example, and I cannot for the life of me figure out why.

Any help would be greatly appreciated.


So in example codepen, they are check for Credentials and then passing the results of that to a function.

So for a simplified way of doing this, try this.