2016-05-30 7 views
0

モーダルコントローラーで私は this.cancel = function()....を使用しようとしていましたが、関数が呼び出されませんでした。 私はそれを$ scope.cancelに変更しなければなりませんでした。それが機能するには、なぜそれが正しいのかを理解しようとしています。

このメインコントローラ

コードでの作業は、スニペットない "何でも":

function MainController($uibModal) { 
    //this works 
    this.popup = function() { 
     $uibModal.open({ 
      controller: 'PopupCtrl', 
      templateUrl: 'myctrl.html'  
    }); 
}; 
} 

function PopupController($scope, $uibModalInstance) { 

    //"this.cancel" does not work, need to use $scope 
$scope.cancel = function(){ 
    $uibModalInstance.dismiss(); 
}; 
//"this" wont work 
    this.ok = function(){ 
    $uibModalInstance.dismiss(); 
    }; 
} 

私はフォーク例に

http://plnkr.co/edit/nMBe6SqXzicxkHNT5JdT

答えて

1

を表示するPlunkerを作成しましたあなたのプランナー。 Thisは、ここで重要な構文
popupctrlがあなたのモーダルコントローラへの参照である「PopupCtrlがpopupctrlとして」ある私のバージョン

this.popup = function() { 
     $uibModal.open({ 
      controller: 'PopupCtrl as popupctrl', 
      templateUrl: 'myctrl.html' 

    }); 

です。私は、「基準」という使用

ng-click="popupctrl.ok()" 

注:ビューでは、私はこれをしませんでした。

+0

素晴らしい!ご協力いただきありがとうございます – VladimirSD

関連する問題