{"action":"created","issue":{"url":"https://api.github.com/repos/Urigo/angular-meteor/issues/1264","repository_url":"https://api.github.com/repos/Urigo/angular-meteor","labels_url":"https://api.github.com/repos/Urigo/angular-meteor/issues/1264/labels{/name}","comments_url":"https://api.github.com/repos/Urigo/angular-meteor/issues/1264/comments","events_url":"https://api.github.com/repos/Urigo/angular-meteor/issues/1264/events","html_url":"https://github.com/Urigo/angular-meteor/issues/1264","id":138904168,"number":1264,"title":"1.3.6: Reactivity not working properly and more","user":{"login":"mattiLeBlanc","id":5285035,"avatar_url":"https://avatars.githubusercontent.com/u/5285035?v=3","gravatar_id":"","url":"https://api.github.com/users/mattiLeBlanc","html_url":"https://github.com/mattiLeBlanc","followers_url":"https://api.github.com/users/mattiLeBlanc/followers","following_url":"https://api.github.com/users/mattiLeBlanc/following{/other_user}","gists_url":"https://api.github.com/users/mattiLeBlanc/gists{/gist_id}","starred_url":"https://api.github.com/users/mattiLeBlanc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mattiLeBlanc/subscriptions","organizations_url":"https://api.github.com/users/mattiLeBlanc/orgs","repos_url":"https://api.github.com/users/mattiLeBlanc/repos","events_url":"https://api.github.com/users/mattiLeBlanc/events{/privacy}","received_events_url":"https://api.github.com/users/mattiLeBlanc/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-03-07T06:59:50Z","updated_at":"2016-03-07T13:02:40Z","closed_at":null,"body":"Hi,\r\n\r\nI am using Angular Meteor quite extensively in the current building of a prototype for a financial company.\r\n\r\nDuring development I ran into a couple of issues, which have been addressed quickly by Urigo ( many thanks for that).\r\n\r\nBut still I think some things of the new API are not working 100% and I am running into issue which cost me a lot of time to track down or work around.\r\n\r\nJust for the sake of reporting, I am going to list them down here. Please feel free to respond or give constructive feedback on how to better do it, if it is not a bug.\r\n\r\nedit: Actually it is one big story holding probably multiple issues but mainly it is related to reactivity.\r\n\r\n** 1) Reactivity with an object: not autorunning after setting of new value**\r\n\r\nI have a simple sort scenario where I have a list of invoices and I have a header with columns. Clicking on the columns need to trigger a sort. For this I created a directive that will capture the click on a specific column and update the scope value of `sortColumns` in the main dashboardController (which holds the invoice list subscription).\r\nThis scope value is the one that should be watched.\r\n```\r\n  updateSort( sortValue: any ): void {\r\n\r\n    console.log( \"updating sort\", sortValue);\r\n    this.sortColumns.__currentColumn  = sortValue;\r\n    this.sortColumns[ sortValue ]     = 1;\r\n    this.$scope.$digest();\r\n  }\r\n\r\n```\r\n\r\nIn BLAZE, I would create a ReactiveVar and that would be it. But unfortunately in Angular I need to watch this variable change somewhere.\r\nBecause I want to filter on my subscription, a template Helper would make sense to me.\r\nI create a helper `invoices`, which will just return a Find() on the invoices subscription. \r\nIn the helper I add \r\n```\r\ntrigger = this.getReactively( 'sortColumns'.__currentColumn );\r\nsort =  angular.copy( this.sortColumns );\r\ndelete sort.__currentColumn;\r\nreturn Invoices.find( {}, { sort: sort } );\r\n```\r\n\r\nThe `updateSort` function is the one I call from the directive because directly accessing the `sortColumns` object and updating did not result in a reactive update in Autorun OR the helper.\r\n\r\nHowever, just updating the object with new key/values did not work either, because watching `sortColumns` alone did not result in a reactive update.\r\nOnly looking specifically looking at `sortColumns.__currentColumn` and updating this property only to trigger the update seems to work.\r\nSo I have to remove the property in my `sort` object so that I can pass the sort object directly to the Mongo Find().\r\n\r\nWith the $digest call, I wouldn't get the update of my sortColumns. Why is this necessary?\r\n\r\nExpected behaviour: \r\n_If I update the object, with whatever content and I am watching the object and not a specific property, I expect a reactive Update, right?_\r\n\r\n\r\n**2) Updating controller variable directly from directive not triggering reactive update** \r\nSo I used the `updateSort` function in the first reported issue, but at first I wanted to directly update that value from the directive. I gave the directive an isolated scope but I assume the value in the directive is always a copy of the value from the controller. So Autorun or ReactiveContext would never watch that copy. So I called a function that updates the value IN the controller. \r\nThis does make sense, so maybe not a bug but I want to validate if this is the best way.\r\n\r\n\r\n**3) Running in a $digest error**\r\nWhen I try to set the initial sorting from my column directive I do it like this: By giving on column a attribute `direction=\"desc\"` and while looping through my columns I look at the one that has a direction attribute and then call the `updateSort` function with the correct column in my dashboardController.\r\n\r\nOn first page run, I get a $digest is already running error. I intentionally call the $digest function in my `updateSort` to make sure during runtime, when a user clicks on the column, a reactive update takes place.\r\nI guess this issue is related to the above mentioned reactive issues and I could remove $digest in the future.\r\n\r\n**4) Subscription stopped issue**\r\nI still run into the subscription stopped issue once in a while. Especially during my issues with the sorting directive, on application auto reload by Meteor I see an empty invoice list. Then reloading by clicking in the address bar and hitting enter a several times work. Or go to another view and go back always seem to work. Not sure what triggers this issue. \r\n\r\nSummary: It took me most of the day to figure out how to get this working and in the end it still feels like a hack. And some fixes trigger errors in other situations, like described in issue 3. \r\n\r\nI think it would be nice to make a bigger list of examples for all kind of scenario's with ReactiveContext, Helpers etc.. That way people can safe time and we are sure noone is hacking the system.\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/Urigo/angular-meteor/issues/comments/193240257","html_url":"https://github.com/Urigo/angular-meteor/issues/1264#issuecomment-193240257","issue_url":"https://api.github.com/repos/Urigo/angular-meteor/issues/1264","id":193240257,"user":{"login":"plraphael","id":645621,"avatar_url":"https://avatars.githubusercontent.com/u/645621?v=3","gravatar_id":"","url":"https://api.github.com/users/plraphael","html_url":"https://github.com/plraphael","followers_url":"https://api.github.com/users/plraphael/followers","following_url":"https://api.github.com/users/plraphael/following{/other_user}","gists_url":"https://api.github.com/users/plraphael/gists{/gist_id}","starred_url":"https://api.github.com/users/plraphael/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/plraphael/subscriptions","organizations_url":"https://api.github.com/users/plraphael/orgs","repos_url":"https://api.github.com/users/plraphael/repos","events_url":"https://api.github.com/users/plraphael/events{/privacy}","received_events_url":"https://api.github.com/users/plraphael/received_events","type":"User","site_admin":false},"created_at":"2016-03-07T13:02:40Z","updated_at":"2016-03-07T13:02:40Z","body":"I'm running into a similar problem as described in 4) Subscription stopped issue.\r\n\r\nBasically, in the page immediately after login, my collection that should have one item after the subscription has none. If I refresh the page, everything goes back to normal. "}}