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 trial

JavaScript AngularJS Basics (1.x) Using Angular's Built In Directives Using ng-repeat to inject HTML for every data element

Ionut Ghita
Ionut Ghita
1,951 Points

Where did "editing" in ng-hide="editing" or ng-click=" editing = !editing" come from?

I can't understand from where did "editing" come from? What is "editing" a variable? Some sort of a function?.....

4 Answers

It came from nowhere! It was created as a property of the current scope by the ng-click directive that was attached to the edit anchor/button.

Basically, when you click on the anchor/button the first time, Angular says "You want to change the property called 'editing' to be the opposite of what it is? Do I have a property called 'editing'? No, I don't. I guess I'll make it!" And thus the mainCtrl scope gets a property named 'editing'. Since it didn't exist yet, Angular assumes that means about the same as 'false' and so running the 'make me opposite' expression on it turns it to 'true'.

It's very convenient and powerful to create scope properties on the fly like this, but also understandably confusing to beginners who are accustomed to declaring all the properties ahead of time. But as you get more into programming, you'll see this done in lots of situations.

Ionut Ghita
Ionut Ghita
1,951 Points

Thanks Marco, I understand what "editing" does and how it used, but what I don't get is from where did it came? Could I have put "zebras" instead of "editing" and get the same results? Actually let me check that.

Ionut Ghita
Ionut Ghita
1,951 Points

Ok. So "zebras" works just as "editing" worked. Which means that "editing" is a made up name.

Agustin Vargas
Agustin Vargas
10,896 Points

Right. It's just a boolean for angular to check if it's true or false and show the input accordingly.

Marco Boretto
Marco Boretto
29,821 Points

hey, i think it's an attribute of the object todo or post or whatever. In this case the attribute editing is a boolean it means it can be true or false. the angularjs ng-click directive in this case switch the value of $scope.todo.editing from true to false and viceversa when the tag is clicked

hope it helps