Skip to content

Instantly share code, notes, and snippets.

@iamblue
Created July 14, 2013 16:18
Show Gist options
  • Select an option

  • Save iamblue/5994810 to your computer and use it in GitHub Desktop.

Select an option

Save iamblue/5994810 to your computer and use it in GitHub Desktop.
<html ng-app="main">
<head>
<style type="text/css">
.active{
color:red;
}
</style>
</head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.1.5/angular.min.js"></script>
<title>基本 AngularJS 練習 - JavaScript 與 AngularJS 開發實戰 (Will 保哥)</title>
<body>
<div ng-controller="selectImg">
<ul>
<li click ng-click="isSelect()" ng-class="{true: 'active', false: 'inactive'}[isActive]">click me1</li>
<li click ng-click="isSelect()" ng-class="{true: 'active', false: 'inactive'}[isActive]">click me23</li>
<li click ng-click="isSelect()" ng-class="{true: 'active', false: 'inactive'}[isActive]">click me3</li>
</ul>
</div>
<script>
var main = angular.module('main', []);
function selectImg($scope) {
$scope.isActive = true;
$scope.isSelect = function () {
if ($scope.isActive === undefined) {
$scope.isActive = true;
} else if ($scope.isActive === true) {
$scope.isActive = false;
} else {
$scope.isActive = true;
}
};
$scope.doSelect = function () {
return $scope.isActive;
};
}
// main.directive("click",function(){
// return function (scope,element,attrs){
// element.bind('click',function(){
// console.log(scope.ele.isActive);
// if (scope.ele.isActive === undefined) {
// scope.ele.isActive = true;
// //console.log('1')
// } else if (scope.ele.isActive === true) {
// scope.ele.isActive = false;
// //console.log('2')
// } else {
// scope.ele.isActive = true;
// // console.log('3')
// }
// })
// }
// })
</script>
</body>
<html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment