I am trying to make a exercise where there are 4 different color boxes and 1 main box below them that is blank, when you click on one of the colored boxes, the main box changes to the color of the box you just clicked on. This seems like a piece of cake with jQuery but I don't know how to do this with Angular
(function() {
'use strict';
function angularBoxesCtrl() {
var vm = this;
vm.mainBoxColor;
vm.logClass = function(e) {
var boxColor = e.target.classList[1];
vm.mainBoxColor = boxColor;
console.log(vm.mainBoxColor);
}
}
angular.module('angularBoxes', [])
.controller('angularBoxesCtrl', [
angularBoxesCtrl
]);
})();
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Angular Boxes</title>
<link rel="stylesheet" href="styles.css">
</head>
<body ng-app="angularBoxes">
<div ng-controller="angularBoxesCtrl as vm" class="boxHolder">
<div ng-click="vm.logClass($event)" class="box green"></div>
<div ng-click="vm.logClass($event)" class="box blue"></div>
<div ng-click="vm.logClass($event)" class="box red"></div>
<div ng-click="vm.logClass($event)" class="box yellow"></div>
</div>
<div class="mainBox" ng-class></div>
<!-- scripts -->
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.js"></script>
<script src="app.js"></script>
</body>
</html>
CSS
div {
box-sizing: border-box;
}
.boxHolder {
border: 1px solid black;
text-align: center;
font-size: 0;
}
.box {
width: 180px;
height: 180px;
display: inline-block;
border: 1px solid black;
margin: 4px;
}
.green {
background-color: green;
}
.blue {
background-color: blue;
}
.red {
background-color: red;
}
.yellow {
background-color: yellow;
}
.mainBox {
width: 400px;
height: 400px;
margin: 0 auto;
border: 1px solid black;
position: relative;
top: 80px;
}