Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialSeth Warner
1,878 PointsJust to make sure I'm doing this right, how to make a function return a true value for the hide AngularJS directive..
html
<div ng-controller="controllerName">
<a href="#" ng-click="coverLetter = !coverLetter"> Cover Letter </a>
<p ng-bind-html show="coverLetter" ng-hide="checkBioFunc()"></p>
<a href="#" ng-click="bio"> Biography </a>
<p ng-bind-html show="bio" ng-hide="checkCoverLetterFunc()" ></p>
</div>
Javascript
$scope.coverLetter = false;
$scope.bio = false;
var checkBio = false;
var checkCoverLetter = false;
function checkBioFunc() {
if ($scope.bio === true) {
checkBio = true;
return checkBio;
}
function checkCoverLetterFunc() {
if ($scope.coverLetter === true)
checkCoverLetter = true;
return checkCoverLetter;
}
1 Answer
Seth Kroger
56,413 PointsFunctions in Angular controllers are declared as properties of $scope as well as the variables. Controllers are written a lot like a constructor function, only you're replacing "this" with "$scope".
$scope.checkBio = function() {
// ...
};
Although I think your logic could be boiled down to a simple "display the cover letter or the bio" based on a single boolean.
<div ng-controller="controllerName">
<a href="" ng-click="coverLetter = true"> Cover Letter </a>
<p ... ng-show="coverLetter"></p>
<a href="#" ng-click="coverLetter = false"> Biography </a>
<p ... ng-hide="coverLetter" ></p>
</div>