单击时,angular-ui bootstap选项卡选择功能

时间:2015-12-13 00:50:29

标签: angularjs angular-ui-bootstrap

尝试使用angular ui bootstrap调用tab选项卡上的表达式函数,但是没有调用表达式,但检查角度检查器是否存在函数/表达式:下面是我的代码工作:

注意:其他标签功能正常

角度视图

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

控制器用作vm

vm.alertMe = alertMe;

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

请帮忙吗?

3 个答案:

答案 0 :(得分:5)

您没有在DOM中调用该函数。

而不是:

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

你应该这样称呼它:

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

答案 1 :(得分:0)

为什么不直接在vm上定义alertMe功能。我看不到你的整个代码。我认为如果你在控制器中正确地将vm指定为this,它应该可以工作。还要确保在html中正确定义了控制器。让我知道:))

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

答案 2 :(得分:0)

始终注入您在角度应用中使用的基本服务名称,在上面的示例中我没有调用:$window服务导致错误/错误。我的最终控制器如下:

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!');
           }
     }
}

和视图,

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