I used jQuery to swap the source of two images so that, when you click one image,it's src will be swapped with the other one added as a data attribute resulting in image change. I wan't to achieve the same using angularjs. I have no strict agenda that it should use src swapping technique itself to achieve the same in angularjs. Anything that is simple and works is fine. Here is my existing code.
jQuery
$(".side-nav li:nth-child(2)").append("<img id='arrowRotate' src='images/prof_arrow1.png' data-swap='images/prof_arrow.png'>");
$("#arrowRotate").click(function() {
var _this = $(this);
var current = _this.attr("src");
var swap = _this.attr("data-swap");
_this.attr('src', swap).attr("data-swap", current);
//toggle li's below
$(".side-nav li:nth-child(3)").toggle();
$(".side-nav li:nth-child(4)").toggle();
$(".side_nav_custom li:nth-child(2) a").toggleClass("orangeSwap");
});
It was easy to achieve the toggle part and I have implemented it in angular (see fiddle). Only thing that bugs me is the src swapping part. I have set up a plunker here.
Angular
index.html
<!DOCTYPE html>
<html>
<head>
<script data-require="angular.js@*" data-semver="1.4.0-beta.3" src="https://code.angularjs.org/1.4.0-beta.3/angular.js"></script>
<link rel="stylesheet" href="style.css" />
<script src="script.js"></script>
</head>
<body ng-app="swap">
<div ng-controller="SwapControl">
<h1>Hello {{myData.names.nameTwo}}!</h1>
<img ng-click="myData.swapHere()" ng-src="{{myData.images.initialImage}}" alt="image to be swapped">
</div>
</body>
</html>
script.js
// Code goes here
var myApp = angular.module("swap", []);
myApp.controller('SwapControl', function($scope) {
$scope.myData = {};
$scope.myData.names = {
nameOne: "Plunker",
nameTwo: "Thomas"
};
$scope.myData.images = {
initialImage: "http://creativecurio.com/wp-content/uploads/2007/vm-logo-sm-1.gif",
finalImage: "http://www.omniaceducation.com/Portals/11164/images/small-logo.jpg"
};
$scope.myData.swapHere = function() {
// swaping takes place here
};
});