2013-05-12 65 views
3

我正在使用Angular JS(與Angular Strap),並試圖讓保存確認對話框工作。如何從Angular Bootstrap模態調用函數(使用角度帶)?

我有一個clear功能,看起來像這樣:

$scope.clear = function(confirm) { 
    if ($scope.dirty && !confirm) { 
    $modal({template: '/save.html', show: true, backdrop: 'static'}); 
    return; 
    } 

    // clear the data 
} 

然後我在我的模態對話框以下按鈕:

<button type="button" class="btn" ng-click="clear(true);hide()">Discard Changes</button> 
<button class="btn btn-primary" ng-click="hide()">Cancel</button> 

這將顯示對話框蠻好的,隱藏它作爲好吧,不管我點擊哪個按鈕。但它永遠不會調用clear函數。這是怎麼回事?

+0

我剛剛在隱藏之前測試過一個函數,它工作正常。 http://plnkr.co/edit/uNpZdPPBcLzy33937Mur?p=preview – lucuma 2013-05-15 14:07:42

+0

在控制器中創建了清晰的功能嗎?另外,你可以使用jsfiddle,plnkr等提供更完整的示例嗎? – 2014-03-04 16:50:46

+0

您調用hide()函數的位置可能已經在新的作用域中創建(例如,如果您使用了ng-if)。嘗試使用$ parent.hide(); – 2014-03-14 18:21:07

回答

1

您需要發送範圍在$模式

$modal({ 
template: '/save.html', 
show: true, 
backdrop: 'static', 
scope: $scope 
}); 

現在($範圍),可以使用$ parent.clear()或只是明確的()的範圍有被髮送到模態。