Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
AngularJS-关闭模态函数不工作_Angularjs_Angular Ui Bootstrap - Fatal编程技术网

AngularJS-关闭模态函数不工作

AngularJS-关闭模态函数不工作,angularjs,angular-ui-bootstrap,Angularjs,Angular Ui Bootstrap,我使用ui.bootstrap创建了一个简单的弹出窗口,但我似乎无法使“确定并关闭”按钮正常工作。我在这个示例代码中遗漏了什么 下面是来自的示例代码 多谢各位 **添加了精确代码图像 关闭和解除是$modal>返回的$modalInstance对象的方法。打开: $scope.open = function() { $scope.$modalInstance = $modal.open({ scope: $scope, templateUrl: "moda

我使用
ui.bootstrap
创建了一个简单的弹出窗口,但我似乎无法使“确定并关闭”按钮正常工作。我在这个示例代码中遗漏了什么

下面是来自的示例代码

多谢各位

**添加了精确代码图像


关闭
解除
$modal>返回的
$modalInstance
对象的方法。打开

$scope.open = function() {
    $scope.$modalInstance = $modal.open({
        scope: $scope,
        templateUrl: "modalContent.html",
        size: '',
    })
};

$scope.ok = function() {
    $scope.$modalInstance.close();
};

$scope.cancel = function() {
    $scope.$modalInstance.dismiss('cancel');
};
代码的另一个问题是需要在模式配置中指定
scope:$scope
。如果希望模态模板内的作用域是定义
ok/cancel
方法的作用域的子作用域,则这是必需的


修复了演示:我用可用版本更新了您的代码

您的代码有一些地方出错

$modal是工厂,不能调用$modal.close()

您需要执行以下操作:

 this.modal = $modal(....)

 this.modal.close();
尽管如此,即使您在控制器中执行了此操作,您的模态视图也无法访问范围

我提供的叉形插入的解决方案是使用

  ng-click="$parent.$close()"

如前所述,有几种方法,这取决于您需要在哪个上下文中使用它

例如,如果模式只是一个通知,则不需要为“确定”或“取消”按钮使用函数,只需在modalContent.html文件中的按钮的ng单击中使用$dismise()或$close()即可

这里还有一个更新的plunker


好啊
取消

我可以跟你进一步核实一下吗?我按照你的指南来实现它,但上面写着“无法读取未定义的属性‘close’”。。。怎么样?感谢意味着你做错了什么。您确定要调用
$modal.open()
返回的对象的
close
方法吗?我已经在上图中添加了我现在拥有的确切代码。。。我还缺少什么吗?是的,还要添加
scope:$scope
$scope.$modalInstance=$modal.open({scope:$scope,templateUrl:'modalContent.html',size:'})
。Angular是Angular的新功能,所有的模态示例都显示了其他控制器,而且都很复杂。
$scope
值帮了我很多忙!!!收银员没能找到没有它的地方:)谢谢!
<div class="modal-footer">
    <button class="btn btn-primary" ng-click="$close()">OK</button>
    <button class="btn btn-warning" ng-click="$dismiss()">Cancel</button>
</div>