我有一个简单的 Angular 模态,是用 Angular ui.bootstrap 引发的。它打开得很好,传递值等,但不会关闭或取消。我认为这是 $scopes 的讨论问题。我知道每个模式都有自己的 $scope,我只是不知道如何让它们相互交谈。
这是模态的标记:
<div>{{entry}}</div>
<button class="btn btn-primary">{{ $modalInstance.close() }}Close</button>
<button class="btn btn-warning" ng-click="cancel()">Cancel</button>
两种方法都尝试了,但都不起作用...
这是“打开”模式的 Controller :
.controller('dashboard',['$scope', '$rootScope', '$location', '$modal', 'loginService', function($scope, $rootScope, $location, $modal, loginService){
var allowed = loginService.authenticate();
allowed.get(
function(result){
console.log(result);
if (result.loggedin !== undefined && result.loggedin === true) {
console.log("Welcome!");
}
},
function(result) {
$location.path("admin");
$rootScope.errorVisible = true;
}
);
$scope.open = function () {
var modalInstance = $modal.open({
templateUrl: '/partials/submission_mod.html',
controller: ['$scope', '$modalInstance', function($scope, $modalInstance){
$scope.modalInstance = $modalInstance;
$scope.entry = "Submission info goes here.";
}]
});
};
}])
现在.. $scope.close 会进入仪表板 Controller 还是仍然尝试坐在自己的 Controller 中,如图 here 所示?
最佳答案
关闭函数需要在 Controller 中。
$scope.open = function () {
var modalInstance = $modal.open({
templateUrl: '/partials/submission_mod.html',
controller: ['$scope', '$modalInstance', function($scope, $modalInstance){
$scope.close = function () {
$modalInstance.dismiss('cancel');
};
$scope.modalInstance = $modalInstance;
$scope.entry = "Submission info goes here.";
}]
});
};
关于javascript - Angular 模态不会关闭(让 $scopes 说话),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29751329/