在我的主页(Index.html)上,点击一个特定的图标,我将通过调用相应的控制器方法打开一个uibmodal (引导)弹出窗口。弹出窗口打开得非常好。在此之后,无法从父控制器捕获弹出控件的按钮单击事件(同意,不同意)。
Controller.js:
function CameraController($scope,$uibModal) {
var vm = this;
vm.captureScreenShot = captureScreenShot;
vm.openCameraAgreement = openCameraAgreement;
/* Opens the agreement before capturing the screen shot */
function openCameraAgreement() {
//open the agreement
var instance = $uibModal.open({
animation: true,
templateUrl: 'app/components/capture/cameraAgreement.html',
controller: CameraController,
controllerAs: 'vm',
size: 'sm-2'
});
vm.cancel = function () {
instance.close();
};
vm.agree = function () {
instance.close();
captureScreenShot() //call this method to do something
};
}
function captureScreenShot($event) {
//do something to capture the screen shot
}
}Index.html:
<li ng-controller="CameraController as camera">
<a ng-click="camera.openCameraAgreement()">
</a>
</li>cameraAgreement.html
<a class="btn btn-primary saveCamera" ng-click="vm.agree()">Agree</a>
<a class="btn btn-primary" ng-click="vm.cancel()">Disagree</a>基本上,我想知道用户点击弹出窗口是同意还是不同意,所以。基于vm.agree()和vm.cancel()的函数没有被调用,也没有错误。我是不是在作用域或控制器引用方面做错了什么?请帮帮忙!
发布于 2016-03-16 05:56:12
尝试将CammeraController $scope添加到您的模态实例,并将您的函数绑定到$scope,如下所示:
var instance = $uibModal.open({
animation: true,
templateUrl: 'app/components/capture/cameraAgreement.html',
controller: CameraController,
controllerAs: 'vm',
size: 'sm-2',
//Add the parent scope
scope: $scope
});
$scope.cancel = function() { ... }发布于 2016-03-16 05:31:27
EDIT:是的,场景是你用两个不同的controller _ is属性注册同一个控制器,所以angular可能会抛出错误,但并不是每个错误都会显示在控制台上。我认为你可以做的是: 1)为modal创建一个新的控制器(函数),并将modal中的函数移动到modal中。2)使用bindToController将函数从相机控制器传递到modal控制器。
https://stackoverflow.com/questions/36022524
复制相似问题