Have a look at:
https://github.com/angular/angular.js/wiki/The-Nuances-of-Scope-Prototypal-Inheritance


On 16 April 2013 22:20, Oren Avissar <notifications@github.com> wrote:

> In src/ng/directive/ngIf.js:
>
> > + * @ngdoc directive
> > + * @name ng.directive:ngIf
> > + * @restrict A
> > + *
> > + * @description
> > + * The `ngIf` directive removes and recreates a portion of the DOM tree (HTML)
> > + * conditionally based on **"falsy"** and **"truthy"** values, respectively, evaluated within
> > + * an {expression}. In other words, if the expression assigned to **ngIf evaluates to a false
> > + * value** then **the element is removed from the DOM** and **if true** then **a clone of the
> > + * element is reinserted into the DOM**.
> > + *
> > + * Note that **when an element is removed using ngIf its scope is destroyed** and **a new scope
> > + * is created when the element is restored**.  Also, `ngIf` recreates elements using their
> > + * compliled state.  For example, if you use jQuery to add a class to an element after it's
> > + * compiled, using something like $('#my-element').addClass('my-class'), 'my-class' will be
> > + * lost if the element is removed and recreated.
>
> In the second part of the paragraph I wanted to point out that if the DOM
> is directly modified (ex. using jQuery) those changes get lost because the
> original compiled element is used for the clone.
>
> I made a test case that shows this situation
>
> function makeIf(expr) {
>   element.append($compile('<div class="my-class" ng-if="' + expr + '"><div>Hi</div></div>')($scope));
>   $scope.$apply();
> }
>
> it('should restore the element to its compiled state', function() {
>   $scope.value = true;
>   makeIf('value');
>   expect(element.children().length).toBe(1);
>   $(element.children()[0]).removeClass('my-class');
>   expect(element.children()[0].className).not.toContain('my-class');
>   $scope.$apply('value = false');
>   expect(element.children().length).toBe(0);
>   $scope.$apply('value = true');
>   expect(element.children().length).toBe(1);
>   expect(element.children()[0].className).toContain('my-class');
> });
>
> Am I missing something? Do you think this should to be in the docs?
>
> Thanks for pointing out the primitive binding issue. I didn't encounter
> that yet. I'll look into it.
>
> —
> Reply to this email directly or view it on GitHub<https://github.com/angular/angular.js/pull/2312/files#r3821554>
> .
>