1

Am trying to call an expression function on tab select using angular ui bootstrap, however the expression is not being called but checking on angular inspector the function /expression exists : below is my code work:

NB : Other tabs function correctly

Angular View

<uib-tab ng-click="vm.alertMe" select="" heading="New Invoice">
                          .....
 </uib-tab>

controller used as vm

vm.alertMe = alertMe;

 function alertMe() {
            setTimeout(function() {
              $window.alert('You\'ve selected the alert tab!');
            });
          } 
1
  • Please don't edit answers into your questions. If you have an answer, post it below and mark it accepted. Commented Dec 15, 2015 at 17:38

3 Answers 3

5

You're not calling the function in your DOM.

instead of this:

<uib-tab ng-click="vm.alertMe" select="" heading="New Invoice">

you should be calling it like this:

<uib-tab ng-click="vm.alertMe()" select="" heading="New Invoice">
Sign up to request clarification or add additional context in comments.

1 Comment

Please refer to above stackoverflow.com/a/34246855/1226748: i was not calling $window service
0

Why not define the alertMe function directly on the vm. I can not see your whole code. I assume it should work if you vm is correctly assigned as this in the controller. Also make sure in the html, your controller is correctly defined. Let me know :)

vm.alertMe = function() {
              setTimeout(function() {
               $window.alert('You\'ve selected the alert tab!');
              });
             } 

3 Comments

I resolved this : I was not calling the $window service to the controller
Oh, you mean you forget to inject that ?
Oh yes kinda in a hurry to finish he app !
0

Always inject the base service names you use in your angular app ,in the above example i was not calling : $window service which resulted in the bug / error .my final controller is as following :

function() {

    'use strict';

    angular
        .module('app.patients')
        .controller('PatientsController', PatientsController);

    PatientsController.$inject = ['$http','$window'];
    /* @nginject */
    function PatientsController($http, $window) { 
       vm.alertMe = function() {

             $window.alert('You\'ve selected the alert tab!');
           }
     }
}

and the view ,

<uib-tab  select="vm.alertMe()" heading="New Invoice">
                          .....
 </uib-tab>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.