{"action":"created","issue":{"url":"https://api.github.com/repos/angular/angular.js/issues/13856","labels_url":"https://api.github.com/repos/angular/angular.js/issues/13856/labels{/name}","comments_url":"https://api.github.com/repos/angular/angular.js/issues/13856/comments","events_url":"https://api.github.com/repos/angular/angular.js/issues/13856/events","html_url":"https://github.com/angular/angular.js/issues/13856","id":129105300,"number":13856,"title":"Form Controller instance maintains incorrect validity properties when its destroyed","user":{"login":"nishantkmr","id":3839330,"avatar_url":"https://avatars.githubusercontent.com/u/3839330?v=3","gravatar_id":"","url":"https://api.github.com/users/nishantkmr","html_url":"https://github.com/nishantkmr","followers_url":"https://api.github.com/users/nishantkmr/followers","following_url":"https://api.github.com/users/nishantkmr/following{/other_user}","gists_url":"https://api.github.com/users/nishantkmr/gists{/gist_id}","starred_url":"https://api.github.com/users/nishantkmr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nishantkmr/subscriptions","organizations_url":"https://api.github.com/users/nishantkmr/orgs","repos_url":"https://api.github.com/users/nishantkmr/repos","events_url":"https://api.github.com/users/nishantkmr/events{/privacy}","received_events_url":"https://api.github.com/users/nishantkmr/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/angular/angular.js/labels/component:%20forms","name":"component: forms","color":"7B947B"},{"url":"https://api.github.com/repos/angular/angular.js/labels/needs:%20more%20info","name":"needs: more info","color":"d7eb9f"},{"url":"https://api.github.com/repos/angular/angular.js/labels/resolution:%20works%20as%20expected","name":"resolution: works as expected","color":"207de5"}],"state":"closed","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/angular/angular.js/milestones/35","html_url":"https://github.com/angular/angular.js/milestones/Purgatory","labels_url":"https://api.github.com/repos/angular/angular.js/milestones/35/labels","id":526241,"number":35,"title":"Purgatory","description":"This milestone is for issues and PRs that weren't accepted yet and we are waiting for more info from the submitter.\r\n\r\nFor issues this typically means that we weren't able to reproduce the issue or we haven't decided yet if a feature request is a good idea at all.\r\n\r\nFor PRs this means that the PR still needs a lot of work and we might not even be interested in merging it because it looks like a non-core feature. We are still waiting for more discussion within the team or more info from the contributor before making the final decision.","creator":{"login":"IgorMinar","id":216296,"avatar_url":"https://avatars.githubusercontent.com/u/216296?v=3","gravatar_id":"","url":"https://api.github.com/users/IgorMinar","html_url":"https://github.com/IgorMinar","followers_url":"https://api.github.com/users/IgorMinar/followers","following_url":"https://api.github.com/users/IgorMinar/following{/other_user}","gists_url":"https://api.github.com/users/IgorMinar/gists{/gist_id}","starred_url":"https://api.github.com/users/IgorMinar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/IgorMinar/subscriptions","organizations_url":"https://api.github.com/users/IgorMinar/orgs","repos_url":"https://api.github.com/users/IgorMinar/repos","events_url":"https://api.github.com/users/IgorMinar/events{/privacy}","received_events_url":"https://api.github.com/users/IgorMinar/received_events","type":"User","site_admin":false},"open_issues":122,"closed_issues":610,"state":"open","created_at":"2014-01-04T01:20:50Z","updated_at":"2016-01-27T18:01:35Z","due_on":null,"closed_at":null},"comments":3,"created_at":"2016-01-27T10:49:32Z","updated_at":"2016-01-27T18:01:35Z","closed_at":"2016-01-27T18:01:35Z","body":"Consider, there is a form which has some validation errors which makes $invalid= true and $errors={...}\r\nNow when the form is destroyed(DOM elements related to form is removed) the watcher function on form will have newValue as undefined and **oldValue will contain formController object with $invalid=false and $errors={}(blank object)**."},"comment":{"url":"https://api.github.com/repos/angular/angular.js/issues/comments/175773945","html_url":"https://github.com/angular/angular.js/issues/13856#issuecomment-175773945","issue_url":"https://api.github.com/repos/angular/angular.js/issues/13856","id":175773945,"user":{"login":"gkalpak","id":8604205,"avatar_url":"https://avatars.githubusercontent.com/u/8604205?v=3","gravatar_id":"","url":"https://api.github.com/users/gkalpak","html_url":"https://github.com/gkalpak","followers_url":"https://api.github.com/users/gkalpak/followers","following_url":"https://api.github.com/users/gkalpak/following{/other_user}","gists_url":"https://api.github.com/users/gkalpak/gists{/gist_id}","starred_url":"https://api.github.com/users/gkalpak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gkalpak/subscriptions","organizations_url":"https://api.github.com/users/gkalpak/orgs","repos_url":"https://api.github.com/users/gkalpak/repos","events_url":"https://api.github.com/users/gkalpak/events{/privacy}","received_events_url":"https://api.github.com/users/gkalpak/received_events","type":"User","site_admin":false},"created_at":"2016-01-27T18:01:35Z","updated_at":"2016-01-27T18:01:35Z","body":"The properties are not incorrect if you take into account what really happens in the DOM.\r\nImagine the following structure:\r\n\r\n```\r\nform ($invalid)\r\n  div[ng-form-1] ($invalid)\r\n    input ($invalid)\r\n```\r\n\r\nWe have an invalid `input`, which makes the parent `ng-form` invalid, which makes the parent `form` invalid (but that's irrelevant).\r\n\r\nWhen you swap `div[ng-form-1]` for `div[ng-form-2]` (but keep the controller of `ng-form-1` around) here is what happens:\r\n\r\n1. The `input` DOM element is removed/destroyed. Upon removal, it looks up to its parent `formController` (i.e. `ng-form-1`) and unregisters itself, because that is what should happen when controls are removed from a form.\r\n2. Once `input` is unregistered from the `ng-form-1` controller, `ng-form-1` does not have any invalid controls (it has no controls at all), so it becomes valid.\r\n3. Then `div[ng-form-1]` is removed from the DOM and unregisters itself from its parent `formController` on the `form` element (which also becomes valid).\r\n\r\nSo, the `ng-form-1` controller (which you keep around) is correctly considered valid, since it has no controls registered with it.\r\n\r\n--\r\nClosing as everything works as expected, but feel free to continue the discussion below."}}