mgcrea / angular-strap

AngularJS 1.2+ native directives for Bootstrap 3.
mgcrea.github.io/angular-strap
MIT License
5.73k stars 1.38k forks source link

alert is not working #1717

Closed gabrielperales closed 9 years ago

gabrielperales commented 9 years ago

I'm trying to make an alert, but I'm not able to make it work. I'm using angularStrap 2.2.2 with bootstrap-sass 3.3.4. My project setup it's something like this:

 var app = angular.module('mymodule',
                           ['constants', 'ngAnimate', 'ngCookies', 'ngTouch', 'ngSanitize', 'restangular', 'ngRoute',
                             'mgcrea.ngStrap', 'mgcrea.ngStrap.modal', 'mgcrea.ngStrap.alert', 'mgcrea.ngStrap.tooltip', 'mgcrea.ngStrap.helpers.parseOptions', 'textAngular']);

And I'm trying to generate an alert dynamically on a controller:

  angular.module('mymodule')
    .controller('MainCtrl', ['$log', '$scope', '$modal', '$alert', 'common',
                function ($log, $scope, $modal, $alert, common) {

                    var myAlert = $alert({
                        'title': 'holamundo'
                    });
                    myAlert.show();
}

This is the message that the console logs:

TypeError: modalLinker is not a function
    at Object.ModalFactory.$modal.show (http://localhost:3000/bower_components/angular-strap/dist/angular-strap.js:1877:44)
    at initialize (http://localhost:3000/app/main/main.controller.js:32:17)

I have follow the instrucctions in the wiki about the component, and I have include the modal plugin needed in theory to make the plugin work.

I have tried to create an element in the html file with the bs-alert attribute, but it still not working...

vmlf01 commented 9 years ago

try doing myAlert.$promise.show(); instead, so the template is loaded and ready before calling show(). Check the docs section on modals also: http://mgcrea.github.io/angular-strap/#/modals-usage

gabrielperales commented 9 years ago

No way, I got this message: TypeError: myAlert.$promise.show is not a function I don't know if I'm doing something wrong... but I can show modals without problems and in theory they should work on the same way, shouldn't they?

@vmlf01 Thank you for your answer.

vmlf01 commented 9 years ago

Sorry, didn't noticed i posted bad code. It should be like this:

myAlert.$promise.then(function() {myAlert.show();});

But in your case, you don't even need to call .show(), because if you don't specify show: false when creating the alert, it will show automatically.

gabrielperales commented 9 years ago

Yes.. it was an example, I was creating the alert hidden and I couldn't understand why it didn't show up. Now it's working :+1:

Thank you @vmlf01

lock[bot] commented 5 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.