2013-05-12 66 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()或只是明确的()的范围有被发送到模态。