簡體   English   中英

單擊時單擊angular-ui引導選項卡選擇功能

[英]angular-ui bootstrap tab select function on click

我試圖使用angular ui引導程序在選項卡選擇上調用表達式函數,但是沒有調用表達式,而是在angular inspector上檢查功能/ expression是否存在:以下是我的代碼:

注意:其他選項卡可正常運行

角度圖

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

您沒有在DOM中調用該函數。

代替這個:

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

您應該這樣稱呼它:

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

為什么不直接在vm上定義alertMe函數。 我看不到您的完整代碼。 我認為它應該工作,如果你VM是正確分配為this控制器。 還要確保在html中,您的控制器已正確定義。 讓我知道 :)

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

總是注入您在angular應用程序中使用的基本服務名稱,在上面的示例中我沒有調用: $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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM