Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Behavior change from 1.2.0-rc3 to 1.2.0 wrt controller creation and ngIf #4921

Closed
matthughes opened this issue Nov 12, 2013 · 3 comments
Closed

Comments

@matthughes
Copy link

In 1.2.0-rc3, if you had both ng-if and ng-controller on the same element, when ng-if condition changed, you would get a new controller. This occurred even if you changed from true -> true. I'm not sure what the expected behavior is here, but in 1.2.0, the controller is only ever instantiated once.

Is this the desired behavior? Is this documented anywhere?

Since this is what I desired in my case, I was able to fix by using both ng-repeat and ng-if:

<div ng-if="selectedItem" ng-repeat="selectedItem in [selectedItem]" ng-controller="ProductController>

</div>

In this example, ng-repeat is what is instantiating the new controller for each new element.

Plunker showing the difference:
http://plnkr.co/edit/uTJSrY0SQI1AdaK2rjJI?p=preview

@matthughes
Copy link
Author

I point this out because I don't know if the fix for the ngIf repeat problem accidentally changed this behavior.

#4893

@petebacondarwin
Copy link
Member

ng-controller has a lower priority than ng-if so it will be reinstantiated each time so you would expect a new controller each time ng-if value changed. I believe there is another PR somewhere the picks up on the fact that if that value goes from true -> true it still reinstantiates.

@IgorMinar
Copy link
Contributor

this was due to a bug in ngIf that was fixed in 1.2.1.

the correct behavior is to create a new controller every time ngIf condition goes from falsy to truthy

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants