We've recently moved to the latest stable version of Angular (1.2.19 at the time of writing) coming from 1.0.8.
They fixed a rather nasty bug regarding isolated scopes, alas one we were (unknowingly) exploiting. I've managed to fix our application, but am now running into (a lot of) issues of the kind "if this property is on the $scope, then ...".
We're getting these issues because we have defined a common structure for our ViewModels. This means that directives making use of this structure will set "non-unique" properties on their scope. Prior to the upgrade, due to the bug, an isolated scope was accessible from it children, but broke the prototypical inheritance. That is exactly why our approach worked.
This is a very simplified view on how our application works (valid in both old and new Angular versions)
<a-directive-with-scope>
I've put the variable foo on my $scope, see: {{foo}}
<a-directive-with-scope>
I've also put the variable foo on my $scope, see: {{foo}}
</a-directive-with-scope>
</a-directive-with-scope>
The problem now is, that the directive does not always set the same properties on the $scope, it depends on what is returned from the back end. So, let's say in the inner directive I want to check if that scope has the id
property, it will return true even if that scope does not have the property, but a parent of his has.
In JavaScript, you can work around these kind of issues by using
if($scope.hasOwnProperty("id")) { ...
But is a same approach possible to fix ngShow
or ngHide
directives? Currently ng-show="id"
won't work because of the prototypical inheritance (as I've explained above).