I am new to AngualrJS. And I am wondering, if ther is some way to toggle between different DIV's.
Let's say, in I have a menu, and by clicking on it, I would like to close current DIV, and open a new one.
A the moment if I one dive is opened and Im clicking at the another one it also appear.
Does any one have an idea, hot to handel this out?
HTML:
<div ng-app="app">
<div ng-controller="MainController">
<div>
<ul>
<li data-ng-repeat="Menu in Menus">
<a class="" href="#" ng-click="show=toggle(Menu)">
{{Menu.id}}
</a>
</li>
</ul>
</div>
<div data-ng-repeat="Menu in Menus" ng-show="Menu.show">
<h2>
{{Menu.text}}
</h2>
</div>
</div>
</div>
And JS:
angular.module('app', []).
controller('MainController', ['$scope', function ($scope) {
$scope.Menus = [{
id: 1,
text: "This is first DIV!!!",
show: true
}, {
id: 2,
text: "This is second DIV!!!",
show: false
}, {
id: 3,
text: "This is third DIV!!!",
show: false
}];
$scope.toggle = function (Menu) {
Menu.show = !Menu.show;
return Menu.show;
};
}]);