gpt4 book ai didi

javascript - Angular js $scope 在 Jquery 函数中不起作用

转载 作者:行者123 更新时间:2023-11-30 07:57:58 25 4
gpt4 key购买 nike

我正在使用 Sweet alert 来获取警报消息。我有确认警报框,确认后我已经禁用了我的内容,但不是禁用 $scope is not working inside swal() 如果点击两次它正在工作。我怎样才能让它工作。我的 HTML 代码:

<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="http://limonte.github.io/sweetalert2/dist/sweetalert2.css">
<script type="text/javascript" src="https://code.jquery.com/jquery-1.11.3.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.min.js"></script>
<script type="text/javascript" src="http://limonte.github.io/sweetalert2/dist/sweetalert2.min.js"></script>
<script type="text/javascript" src="js/myscript.js"></script>
</head>
<body ng-app="app" ng-controller="myController">

Supplier ID:<input type="text" ng-model="supplierID" ng-disabled="disable"/><br>
Series ID:<input type="text" ng-model="seriesID" ng-disabled="disable"/><br>
SKU ID:<input type="text" ng-model="skuID" ng-disabled="disable"/><br><br>
<div class="action-keys">
<button class="btn btn-default" ng-click="enable()" ng-disabled="!disable">Enable</button>
<button class="btn btn-default" ng-click="disableCall()" ng-disabled="disable">Disable</button>
</div>
</body>

和我的myscript.js:

angular.module('app', [])
.controller('myController', function($scope) {
$scope.disable = false;
$scope.disableCall = function () {
swal(
{
title: 'Warning',text: 'Are you want to disable?',type: 'warning',showCancelButton: true,confirmButtonColor: '#3085d6',cancelButtonColor: '#d33',
confirmButtonText: 'Yes',cancelButtonText: 'No',confirmButtonClass: 'confirm-class',cancelButtonClass: 'cancel-class',allowOutsideClick : false
},function(isConfirm) {
if (isConfirm) {
$scope.skuID = '';
$scope.seriesID = '';
$scope.supplierID = '';
$scope.disable = true;
}else{
return;
}
});
}
$scope.enable = function () {
$scope.skuID = '';
$scope.seriesID = '';
$scope.supplierID = '';
$scope.disable = false;

}
});

我的示例代码启用工作正常,确认中的禁用功能不起作用。请帮忙解决这个问题。提前致谢。

最佳答案

当某些事情发生在 Angular 之外时,只需使用 $scope.$apply。注意调用

$scope.$apply(function(){
//everything here will trigger digest cycle
//everything...
});

angular.module('app', [])
.controller('myController', function($scope) {
$scope.disable = false;
$scope.disableCall = function () {
swal(
{
title: 'Warning',text: 'Are you want to disable?',type: 'warning',showCancelButton: true,confirmButtonColor: '#3085d6',cancelButtonColor: '#d33',
confirmButtonText: 'Yes',cancelButtonText: 'No',confirmButtonClass: 'confirm-class',cancelButtonClass: 'cancel-class',allowOutsideClick : false
},function(isConfirm) {
if (isConfirm) {
$scope.$apply(function(){
$scope.skuID = '';
$scope.seriesID = '';
$scope.supplierID = '';
$scope.disable = true;
});
}else{
return;
}
});
}
$scope.enable = function () {
$scope.skuID = '';
$scope.seriesID = '';
$scope.supplierID = '';
$scope.disable = false;

}
});
<link rel="stylesheet" href="http://limonte.github.io/sweetalert2/dist/sweetalert2.css">
<script type="text/javascript" src="https://code.jquery.com/jquery-1.11.3.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.min.js"></script>
<script type="text/javascript" src="http://limonte.github.io/sweetalert2/dist/sweetalert2.min.js"></script>


<div ng-app="app" ng-controller="myController">

Supplier ID:<input type="text" ng-model="supplierID" ng-disabled="disable"/><br>
Series ID:<input type="text" ng-model="seriesID" ng-disabled="disable"/><br>
SKU ID:<input type="text" ng-model="skuID" ng-disabled="disable"/><br><br>
<div class="action-keys">
<button class="btn btn-default" ng-click="enable()" ng-disabled="!disable">Enable</button>
<button class="btn btn-default" ng-click="disableCall()" ng-disabled="disable">Disable</button>
</div>
</div>

关于javascript - Angular js $scope 在 Jquery 函数中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35340460/

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