{"action":"created","issue":{"url":"https://api.github.com/repos/angular/angular.js/issues/14798","repository_url":"https://api.github.com/repos/angular/angular.js","labels_url":"https://api.github.com/repos/angular/angular.js/issues/14798/labels{/name}","comments_url":"https://api.github.com/repos/angular/angular.js/issues/14798/comments","events_url":"https://api.github.com/repos/angular/angular.js/issues/14798/events","html_url":"https://github.com/angular/angular.js/pull/14798","id":161077418,"number":14798,"title":"feat($rootScope): allow $watch to be triggered by an event","user":{"login":"odedniv","id":894198,"avatar_url":"https://avatars.githubusercontent.com/u/894198?v=3","gravatar_id":"","url":"https://api.github.com/users/odedniv","html_url":"https://github.com/odedniv","followers_url":"https://api.github.com/users/odedniv/followers","following_url":"https://api.github.com/users/odedniv/following{/other_user}","gists_url":"https://api.github.com/users/odedniv/gists{/gist_id}","starred_url":"https://api.github.com/users/odedniv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/odedniv/subscriptions","organizations_url":"https://api.github.com/users/odedniv/orgs","repos_url":"https://api.github.com/users/odedniv/repos","events_url":"https://api.github.com/users/odedniv/events{/privacy}","received_events_url":"https://api.github.com/users/odedniv/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/angular/angular.js/labels/cla:%20yes","name":"cla: yes","color":"bfe5bf"},{"url":"https://api.github.com/repos/angular/angular.js/labels/component:%20scopes","name":"component: scopes","color":"fbca04"},{"url":"https://api.github.com/repos/angular/angular.js/labels/frequency:%20high","name":"frequency: high","color":"f7c6c7"},{"url":"https://api.github.com/repos/angular/angular.js/labels/severity:%20inconvenient","name":"severity: inconvenient","color":"006b75"},{"url":"https://api.github.com/repos/angular/angular.js/labels/type:%20feature","name":"type: feature","color":"00a606"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/angular/angular.js/milestones/38","html_url":"https://github.com/angular/angular.js/milestones/Ice%20Box","labels_url":"https://api.github.com/repos/angular/angular.js/milestones/38/labels","id":529901,"number":38,"title":"Ice Box","description":"Milestone for valid issues and bugs that we have no aspirations on fixing any time soon because they are not affecting primary use-cases and are not aligned with our goals.","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":187,"closed_issues":289,"state":"open","created_at":"2014-01-08T08:19:21Z","updated_at":"2016-06-27T13:30:46Z","due_on":null,"closed_at":null},"comments":9,"created_at":"2016-06-19T15:15:30Z","updated_at":"2016-06-27T14:17:29Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/angular/angular.js/pulls/14798","html_url":"https://github.com/angular/angular.js/pull/14798","diff_url":"https://github.com/angular/angular.js/pull/14798.diff","patch_url":"https://github.com/angular/angular.js/pull/14798.patch"},"body":"**Note:** I did not yet add documentation/tests because I first want to know if this actually makes sense to do this.\r\n\r\n**What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)**\r\nfeat\r\n\r\n**What is the current behavior? (You can also link to an open issue here)**\r\nWatch expressions are always evaluated on every digest.\r\n\r\n**What is the new behavior (if this is a feature change)?**\r\nAllow `$watch` to be evaluated when an event is triggered (using `$on`), with a new syntax `\"eventName: watchExpression\"`.\r\n\r\nExample:\r\n\r\n*HTML:*\r\n```html\r\n<div ng-if=\"sessionChanged: currentUser\">\r\n  <!-- Below doesn't really work yet since I don't know where that is -->\r\n  Hi, {{sessionChanged: currentUser.username}}\r\n</div>\r\n```\r\n\r\n*JavaScript:*\r\n```javascript\r\n$rootScope.currentUser = { username: \"...\" };\r\n$rootScope.$broadcast('sessionChanged');\r\n```\r\n\r\n**Does this PR introduce a breaking change?**\r\nNo.\r\n\r\n**Other information**:\r\nThis is actually more of a suggestion/question: I read everywhere that watchers are bad, but there is no true solution for this apart from writing directives that basically destroy the templating concept. I understand that using events (`$on`) should be better, and so I figured it might be a good idea to patch into `$watch` (which is used everywhere, `ng-if` etc) the ability to be triggered by an event rather than adding it to the digest cycle."},"comment":{"url":"https://api.github.com/repos/angular/angular.js/issues/comments/228758515","html_url":"https://github.com/angular/angular.js/pull/14798#issuecomment-228758515","issue_url":"https://api.github.com/repos/angular/angular.js/issues/14798","id":228758515,"user":{"login":"odedniv","id":894198,"avatar_url":"https://avatars.githubusercontent.com/u/894198?v=3","gravatar_id":"","url":"https://api.github.com/users/odedniv","html_url":"https://github.com/odedniv","followers_url":"https://api.github.com/users/odedniv/followers","following_url":"https://api.github.com/users/odedniv/following{/other_user}","gists_url":"https://api.github.com/users/odedniv/gists{/gist_id}","starred_url":"https://api.github.com/users/odedniv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/odedniv/subscriptions","organizations_url":"https://api.github.com/users/odedniv/orgs","repos_url":"https://api.github.com/users/odedniv/repos","events_url":"https://api.github.com/users/odedniv/events{/privacy}","received_events_url":"https://api.github.com/users/odedniv/received_events","type":"User","site_admin":false},"created_at":"2016-06-27T14:17:29Z","updated_at":"2016-06-27T14:17:29Z","body":"@gkalpak how can it be implemented without patching scope watches? Can you give an example? All I can think of is a directive that recompiles the entire element when an event triggers..."}}
{"actor":{"display_login":"odedniv"}}