0

我有我的模式設置爲使角UI引導模式按鈕將不執行功能

<script type="text/ng-template" id="myModalContent.html"> 
    <div class="modal-header"> 
     <h3 class="modal-title">Confirm</h3> 
    </div> 
    <div class="modal-body"> 
     <p>Are you sure you want to remove Two Factor Authentication from your profile?</p> 
    </div> 
    <div class="modal-footer"> 
     <button class="btn btn-primary" ng-click="removeSetting()">Yes</button> 
     <button class="btn btn-warning" ng-click="$dismiss()">Cancel</button> 
    </div> 
</script> 

擊中取消按鈕做什麼它應該直接關閉模式。我的問題出現在用戶點擊yes按鈕時。我的功能removeSetting()從未得到執行。

$scope.removeSetting = function() { 
     TwoFactorAuthenticationService.removetAuthetication().then(function(data) { 
      $scope.busy3=false; 
      notifyService.alert("error", notifyService.getAlertText('2FactorRemovedToken')); 
      $scope.busy=true; 
      $timeout(function() { 
       $scope.templateUrl = 'twofactorsetup/step1.html'; 
      }, 3000); 
     }, function() { 
      notifyService.alert("error", notifyService.getAlertText('2FactorRemoveTokenFailed')); 
     }); 
    }; 

這是應該調用和執行的函數。我錯過了什麼?在模式

+1

是該功能被擊中或不使用呼叫功能從父範圍從這樣的模板?你有沒有放置任何'調試器',看看? –

+0

是範圍函數(嘗試在templa中顯示removeSetting變量) 如果在範圍內,它是否進入它(在開始時添加日誌) - 可以有例如。承諾或缺少$的某些問題適用於結果函數。很難猜到 – farincz

+0

你是如何打開你的模態?你在你的模式中給了哪個控制器?它的功能是什麼? –

回答

0

廣場這樣的代碼初始化

$modal.open({ 
    templateUrl: 'myModalContent.html', 
    scope: $scope, 
    controller: function($scope, $modalInstance) { 
     $scope.removeSetting = function() { 
      //place your code here or call function from parent scope 
      $scope.$parent.removeSetting(); 
      $modalInstance.dismiss('cancel'); 
     }; 
    } 
}); 

如果不使用父作用域你不需要範圍參數。

或者你也可以(通過使用$ parent.removeSetting()調用)

<script type="text/ng-template" id="myModalContent.html"> 
    <div class="modal-header"> 
     <h3 class="modal-title">Confirm</h3> 
    </div> 
    <div class="modal-body"> 
     <p>Are you sure you want to remove Two Factor Authentication from your profile?</p> 
    </div> 
    <div class="modal-footer"> 
     <button class="btn btn-primary" ng-click="$parent.removeSetting()">Yes</button> 
     <button class="btn btn-warning" ng-click="$dismiss()">Cancel</button> 
    </div> 
</script>