{"action":"created","issue":{"url":"https://api.github.com/repos/johnpapa/angular-styleguide/issues/462","labels_url":"https://api.github.com/repos/johnpapa/angular-styleguide/issues/462/labels{/name}","comments_url":"https://api.github.com/repos/johnpapa/angular-styleguide/issues/462/comments","events_url":"https://api.github.com/repos/johnpapa/angular-styleguide/issues/462/events","html_url":"https://github.com/johnpapa/angular-styleguide/issues/462","id":98179662,"number":462,"title":"Recommend against controllerAs vm","user":{"login":"wesleycho","id":1703387,"avatar_url":"https://avatars.githubusercontent.com/u/1703387?v=3","gravatar_id":"","url":"https://api.github.com/users/wesleycho","html_url":"https://github.com/wesleycho","followers_url":"https://api.github.com/users/wesleycho/followers","following_url":"https://api.github.com/users/wesleycho/following{/other_user}","gists_url":"https://api.github.com/users/wesleycho/gists{/gist_id}","starred_url":"https://api.github.com/users/wesleycho/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wesleycho/subscriptions","organizations_url":"https://api.github.com/users/wesleycho/orgs","repos_url":"https://api.github.com/users/wesleycho/repos","events_url":"https://api.github.com/users/wesleycho/events{/privacy}","received_events_url":"https://api.github.com/users/wesleycho/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-07-30T14:11:40Z","updated_at":"2015-07-30T18:11:50Z","closed_at":null,"body":"There has been talk over the past few months about the `vm` pattern - `var ctrl = this` seems to almost unilaterally be preferred by all of the experts I have talked to (& by myself), but this is minor.\r\n\r\nThe problematic recommendations are `controllerAs: vm` and `Foo as vm` - this is less searchable, as well as obfuscating the name. For example, `Auth as auth` would allow the user to describe in the template more appropriately, such as `<form ng-submit=\"auth.login()\">` - human readability is much better, as well as searchability due to being able to quickly identify the template of interest. Doing `grep -r 'auth' src/` is sure to return much more relevant results than `grep -r 'vm' src/`, and similarly for any other project-wide searches."},"comment":{"url":"https://api.github.com/repos/johnpapa/angular-styleguide/issues/comments/126421925","html_url":"https://github.com/johnpapa/angular-styleguide/issues/462#issuecomment-126421925","issue_url":"https://api.github.com/repos/johnpapa/angular-styleguide/issues/462","id":126421925,"user":{"login":"dietergeerts","id":7393706,"avatar_url":"https://avatars.githubusercontent.com/u/7393706?v=3","gravatar_id":"","url":"https://api.github.com/users/dietergeerts","html_url":"https://github.com/dietergeerts","followers_url":"https://api.github.com/users/dietergeerts/followers","following_url":"https://api.github.com/users/dietergeerts/following{/other_user}","gists_url":"https://api.github.com/users/dietergeerts/gists{/gist_id}","starred_url":"https://api.github.com/users/dietergeerts/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dietergeerts/subscriptions","organizations_url":"https://api.github.com/users/dietergeerts/orgs","repos_url":"https://api.github.com/users/dietergeerts/repos","events_url":"https://api.github.com/users/dietergeerts/events{/privacy}","received_events_url":"https://api.github.com/users/dietergeerts/received_events","type":"User","site_admin":false},"created_at":"2015-07-30T18:11:50Z","updated_at":"2015-07-30T18:11:50Z","body":"vm stands for ViewModel and imho is a far better name than ctrl, which stands for controller. Yes I know that Angular had chosen the name Controller, but they are used as a ViewModel, hence they are a model for your view. Many people (including experts) have worked more with controllers than with viewmodels, that's why they prefer controller, which I think is wrong. ViewModel is just so much more flexible and self contained.\r\n\r\nAbout the use of `as vm`, you can choose what you call it. The view only have to know what it will be called when the controller is set through route or ngInclude, but that's no problem as views are always build for certain viewmodel(s). I prefer just vm, as you know it is a viewmodel... Never had problems with searchability, one view is for one viewmodel."}}