angularjs中的選項卡例項
阿新 • • 發佈:2018-11-09
angularjs中的bug ng-click,賦值,ng-repeat三個一起用會有bug
一個angularjs的選項卡
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>angularjs中的選項卡</title> <script src="https://cdn.staticfile.org/angular.js/1.5.5/angular.min.js"></script> <style> .box input.active{ background:yellow } .box div{ width:200px; height:200px; background:#CCC; border:1px solid black; display:none } .box div.cur { display:block; } </style> </head> <!--angularjs中的bug ng-click,賦值,ng-repeat三個一起用會有bug--> <body ng-app="tab_switch"> <div ng-controller="test"> <div class="box"> <input type="button" ng-repeat="(k,v) in items" value="{{k}}"class="{{$index==now?'active':''}}" ng-click="setNow($index)" /> <!--angularjs中的bug ng-click,賦值,ng-repeat三個一起用會有bug--> <!--<input type="button" ng-repeat="(k,v) in items" value="{{k}}" class="{{$index==now?'active':''}}" ng-click="now=$index" />--> <div class="{{$index==now?'cur':''}}" ng-repeat="v in items"> {{v}} </div> </div> </div> <script type="text/javascript"> let mod = angular.module("tab_switch", []); mod.controller("test", ["$scope", function ($scope) { $scope.now = 0; $scope.items = { "按鈕1": "ssssds", "按鈕2": "ddddd", "按鈕3":"fffff" }; $scope.setNow = function (num) { $scope.now = num; } }]); </script> </body> </html>