Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/440.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 用AngularJS单击后切换按钮_Javascript_Angularjs_Angularjs Ng Click_Angularjs Ng Show - Fatal编程技术网

Javascript 用AngularJS单击后切换按钮

Javascript 用AngularJS单击后切换按钮,javascript,angularjs,angularjs-ng-click,angularjs-ng-show,Javascript,Angularjs,Angularjs Ng Click,Angularjs Ng Show,当我点击API上的按钮时,运行xhr来“激活”我的数据。但当我点击“关闭”按钮时,我的API运行XHR以“取消激活”我的数据。我从数据API(0或1)中获得了isactive。因此,我使用_ ng显示和ng隐藏 我确实显示了我的按钮“关”或“开”,以显示我的isactive==1或isactive==0 我使用了以下代码HTML: <button ng-show="data.active" type="button" class="btn btn-default" ng-click="Fi

当我点击API上的按钮时,运行xhr来“激活”我的数据。但当我点击“关闭”按钮时,我的API运行XHR以“取消激活”我的
数据。我从数据API(0或1)中获得了isactive
。因此,我使用_

ng显示和ng隐藏

我确实显示了我的按钮“关”或“开”,以显示我的
isactive==1
isactive==0

我使用了以下代码HTML:

<button ng-show="data.active" type="button" class="btn btn-default" ng-click="FiturThread(data)"><i class="fa fa-toggle-off"></i> Off</button>
<button ng-hide="data.active" type="button" class="btn btn-success" ng-click="FiturThread(data)"><i class="fa fa-toggle-on"></i> On</button>
关闭
在…上
我的问题是我点击了按钮“开”和警报运行“成功激活”,按钮“开”应该替换为按钮“关”,所以取而代之


你能给我一个解决方案吗?我必须用什么?谢谢

以下是工作示例

试试这个


第一个按钮
第二个按钮
var-app=angular.module('myApp',[]);
应用程序控制器('myCtrl',函数($scope){
$scope.data={};
$scope.data.active=true;
$scope.FiturThread=function(){
$scope.data.active=!$scope.data.active;
}
});

您的html看起来不错,数据一定有问题,我建议您检查浏览器中xhr调用的响应。响应xhr是正确的,我想结果是数据数组,您可以编写ng repeat对每个数据执行主动/非主动。在那个ng重复里面,按钮保持不变。我明白这一点。是吗?是的,是的。我的意思是你的代码没有显示错误,但仍然不工作。按钮未切换,console.log良好且无错误显示更多代码以便我能够理解我只需使用“ng repeat=“data in result”获取“data.active”和html。就这样。