簡體   English   中英

從控制器控制角度指令

[英]Controlling Angular Directive From Controllers

我有一個angular指令,其作用類似於登錄popup.this指令會打開一個彈出頁面。

modal = angular.module('Directive.Modal',[]);



modal.directive('modalLogin',function()
{   
    return {

      restrict: 'EA',
      scope:true,
      scope :
      {
        header : "=",
        callback : "&",
        email : "=",
        password : "=",
        button : "=",
        show : "&"
      },
      templateUrl: 'directiveTemplate/modalWelcome.html',
      link : function(scope,element,attrs)
      {
            scope.$watch("show",function()
            {
                console.log("Inner Function Clicked");

            });
       }

      }


});

但是,在使用bootstrap.ui之后,我看到我可以直接從我的控制器中使用一根襯板調用模態。 這是我要實現的目標,因為我如何使用控制器中的一根襯板創建模態/自定義模態。

下面的代碼在我的html中

<!-- Login PopUP Modal Directive -->
<modal-login 
header="ModalPageHeader"  
email="ModalPageEmail"
password="ModalPagePass"
button="ModalPageButton"
ng-click="getAuth()" 
></modal-login>

下面是控制器中的代碼

app.controller('indexGlobalCtrl', function($scope,$location,ngDialog) {


    $scope.ModalPageHeader ="Login Page";
    $scope.ModalPageEmail ="Username As E-Mail";
    $scope.ModalPagePass = "Password";
    $scope.ModalPageButton = "Login";

 //   $scope.dismiss();


    $scope.getAuth = function()
    {
        alert("sd");
        $scope.show = !$scope.show;

    };
}

這是我創建的指令。 雖然我可以使用ng-show和ng-hide,但我的要求是創建一個可切換模式的線性襯墊API。 1.如何以編程方式控制它

任何幫助,將不勝感激。

您無需創建指令即可打開模態。您可以通過使用$ modal.open()從控制器中打開指令,如angular ui.bootstrap中所述。這是angular ui.bootstrap文檔的鏈接https:// angular- ui.github.io/bootstrap/

暫無
暫無

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

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