我有一个div点击我调用方法。 现在,有一个“取消”按钮,点击它我将$ scope.variable设置为true。
接下来,我只需在$ scope.variable设置为false的情况下点击'div'就可以执行我的函数。
但它现在工作!你能帮我解决这个问题吗?
这里是我的代码:
angular.module('app', ['ngSanitize']).controller('Ctrl', function($scope) {
$scope.stopFunc = function() {
$scope.stopFuncExec = true;
}
$scope.stopFuncExec == false;
$scope.myFunc1 = function() {
console.log("Inside " + $scope.stopFuncExec);
var whoAreYou = "Coder";
if (whoAreYou == "Coder" && $scope.stopFuncExec == false) {
console.log("Hello, stop me if you can!");
}
}
});
.parent {
height: 100px;
width: 200px;
background: skyblue;
border: 1px solid lightgrey;
border-radius: 5px;
padding: 20px;
margin: 20px;
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<div ng-app="app" ng-controller="Ctrl">
<div class="parent">
<div ng-click="myFunc1()">Click Me!</div>
</div>
<button ng-click="stopFunc()">Cancel</button>
</div>
你可能已经编辑[这个问题](https://stackoverflow.com/q/46745248/2435473) –
是的,我很抱歉。但是,那么在这个问题上改变我自己的错误代码是不正确的。因此,我在这里添加了它,你能帮忙吗? – Sunny