Join the Stack Overflow Community
Stack Overflow is a community of 6.6 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

angular-ui-modal]1 for create my site and I want to show my modal automatically when the user enter in my webpage. With ng-click is easy , I have this code:

var app = angular.module('app', ['ui.bootstrap']);
app.controller('HomeCtrl', ['$scope', '$modal', function($scope, $modal) {
$scope.openModal = function(data) {
  var modalInstance = $modal.open({
    templateUrl: 'modals/register.html',
    resolve: {
      data: function() {
        return data === null ? {} : data;
      }
    }
  });
};
}]);

But I do not know how trigger the modal when load page. Any help? Please

share|improve this question
    
Just call the same code outside of the scope function. Also $modal is an old version so you may want to consider upgrading. – Matthew Green Jan 16 at 16:10
    
Possible duplicate of Bootstrap-angular-ui modal on load – Mike McCaughan Jan 16 at 17:41
up vote 0 down vote accepted

You just have to call the function when the controller is loaded:

var app = angular.module('app', ['ui.bootstrap']);
app.controller('HomeCtrl', ['$scope', '$modal', function($scope, $modal) {
  $scope.openModal = function(data) {
    $scope.blurred  = "blurredopen";
    var modalInstance = $modal.open({
      templateUrl: 'modals/register.html',
      resolve: {
        data: function() {
          return data === null ? {} : data;
        }
      }
    });
  };

  $scope.openModal(); // <-- Call it
}]);

Demo on JSFiddle

share|improve this answer
    
it does not work :S – lordf Jan 16 at 16:21
    
Added a JSFiddle demo. Be sure you call $scope.openModal() after declaring the function. – Mistalis Jan 16 at 16:22
    
yeah now works fine... thanks :) – lordf Jan 16 at 16:35
    
other question @Mistalis , if i want the modal appears after x seconds? Thanks for your help – lordf Jan 16 at 17:59
1  
use $timeout, if you've found Mistalis's answer helpful then please accept or at least upvote it. – svarog Jan 16 at 18:20

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.