I'm trying to use AngularJS to create a simple click to bold effect. I hope not to involve any controller scripts, but included or not, my code just don't work.
My HTML code with angular markup
<div ng-app="organHome">
<dl class="sub-nav" ng-controller="inModalSwitchCtrl">
<dd ng-class="content:bold"><a ng-click="switchContent()" ng-model="content">Contents</a>
</dd>
<dd ng-class="comment:bold"><a ng-model="comment" ng-click="switchComment()">Comments</a>
</dd>
</dl>
</div>
My js code:
angular.module('organHome', [])
.controller('inModalSwitchCtrl', function ($scope) {
$scope.content = true;
$scope.comment = false;
$scope.switchContent = function ($scope) {
$scope.content = true;
$scope.comment = false;
};
$scope.switchComment = function ($scope) {
$scope.comment = true;
$scope.content = false;
};
});
Here is the example on fiddle
I know it must be very rookie-ish, but I'm stuck. Any help?
My original goal was to minimize my code, and hopefully no controller.js at all.
If there is anyway to just do it with existing directives, I would love to follow!
My horrible and not working approach looks like this:
<dl class="sub-nav">
<dd ng-class="'active':content"><a ng-click="content = true" ng-model="content">Contents</a></dd>
<dd ng-class="'active':comment"><a ng-model="comment">Comments</a></dd>
</dl>