gpt4 book ai didi

javascript - Angular 模态不会关闭(让 $scopes 说话)

转载 作者:行者123 更新时间:2023-11-28 19:16:16 29 4
gpt4 key购买 nike

我有一个简单的 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/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com