I have a pair of span tags and p tags as follows:
<span class="span1" ng-click="show()">Span_1</span>
<p class="p1" ng-show="var1">P_1</p>
<span class="span2" ng-click="show()">Span_2</span>
<p class="p2" ng-show="var1">P_2</p>
Using AngularJS, my goal is to create a single function like "show()" above that toggles both p tags. How can I achieve this? Here's the corresponding JavaScript code:
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.var1 = false;
$scope.show = function() {
$scope.var1 = $scope.var1 === false ? true: false;
};
});
When I click on Span_1, only the corresponding p tag should show, same for Span_2. This functionality should be achieved using just one function.
Check out the Plunker example here: http://plnkr.co/edit/fzgpV68Q7UnHGHmHffZZ?p=preview