{"action":"created","issue":{"url":"https://api.github.com/repos/paradox41/angular-chartist.js/issues/25","labels_url":"https://api.github.com/repos/paradox41/angular-chartist.js/issues/25/labels{/name}","comments_url":"https://api.github.com/repos/paradox41/angular-chartist.js/issues/25/comments","events_url":"https://api.github.com/repos/paradox41/angular-chartist.js/issues/25/events","html_url":"https://github.com/paradox41/angular-chartist.js/issues/25","id":52311435,"number":25,"title":"Watch chart type attribute?","user":{"login":"Rodeoclash","id":63807,"avatar_url":"https://avatars.githubusercontent.com/u/63807?v=3","gravatar_id":"","url":"https://api.github.com/users/Rodeoclash","html_url":"https://github.com/Rodeoclash","followers_url":"https://api.github.com/users/Rodeoclash/followers","following_url":"https://api.github.com/users/Rodeoclash/following{/other_user}","gists_url":"https://api.github.com/users/Rodeoclash/gists{/gist_id}","starred_url":"https://api.github.com/users/Rodeoclash/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Rodeoclash/subscriptions","organizations_url":"https://api.github.com/users/Rodeoclash/orgs","repos_url":"https://api.github.com/users/Rodeoclash/repos","events_url":"https://api.github.com/users/Rodeoclash/events{/privacy}","received_events_url":"https://api.github.com/users/Rodeoclash/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/paradox41/angular-chartist.js/labels/enhancement","name":"enhancement","color":"84b6eb"}],"state":"closed","locked":false,"assignee":{"login":"paradox41","id":2791730,"avatar_url":"https://avatars.githubusercontent.com/u/2791730?v=3","gravatar_id":"","url":"https://api.github.com/users/paradox41","html_url":"https://github.com/paradox41","followers_url":"https://api.github.com/users/paradox41/followers","following_url":"https://api.github.com/users/paradox41/following{/other_user}","gists_url":"https://api.github.com/users/paradox41/gists{/gist_id}","starred_url":"https://api.github.com/users/paradox41/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/paradox41/subscriptions","organizations_url":"https://api.github.com/users/paradox41/orgs","repos_url":"https://api.github.com/users/paradox41/repos","events_url":"https://api.github.com/users/paradox41/events{/privacy}","received_events_url":"https://api.github.com/users/paradox41/received_events","type":"User","site_admin":false},"milestone":null,"comments":31,"created_at":"2014-12-18T00:32:09Z","updated_at":"2015-01-19T23:13:00Z","closed_at":"2015-01-17T18:20:21Z","body":"What do you think about watching the chart type and rebuilding the chart if it changes?"},"comment":{"url":"https://api.github.com/repos/paradox41/angular-chartist.js/issues/comments/70577700","html_url":"https://github.com/paradox41/angular-chartist.js/issues/25#issuecomment-70577700","issue_url":"https://api.github.com/repos/paradox41/angular-chartist.js/issues/25","id":70577700,"user":{"login":"Rodeoclash","id":63807,"avatar_url":"https://avatars.githubusercontent.com/u/63807?v=3","gravatar_id":"","url":"https://api.github.com/users/Rodeoclash","html_url":"https://github.com/Rodeoclash","followers_url":"https://api.github.com/users/Rodeoclash/followers","following_url":"https://api.github.com/users/Rodeoclash/following{/other_user}","gists_url":"https://api.github.com/users/Rodeoclash/gists{/gist_id}","starred_url":"https://api.github.com/users/Rodeoclash/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Rodeoclash/subscriptions","organizations_url":"https://api.github.com/users/Rodeoclash/orgs","repos_url":"https://api.github.com/users/Rodeoclash/repos","events_url":"https://api.github.com/users/Rodeoclash/events{/privacy}","received_events_url":"https://api.github.com/users/Rodeoclash/received_events","type":"User","site_admin":false},"created_at":"2015-01-19T23:13:00Z","updated_at":"2015-01-19T23:13:00Z","body":"I had to write a Plunkr to try and figure this out for myself. Calling ```&``` will not copy the object being passed in, it's still passed by object reference.\r\n\r\nHere's a Plunkr where a directive fetches the data object of its parent controller by calling ```&```. You'll see that modifications to the data object in the directive still affect the parent controller.\r\n\r\nhttp://plnkr.co/edit/nyxYRTb3CIxItGXjIcE1?p=preview\r\n\r\nIt seems to me that your watch function is simply watching the dereferenced contents of the ```&``` which happens to be the parent controller / directives data. The reason you had the problem watching all the scope items in an array is correct, you're watching the string contents of a function which returns data from the parent scope. However, even if the watch function executed the ```&``` function though, you'd still get an object that was referenced to the parent controllers data.\r\n\r\n**I totally agree with making the directive read only** but I don't think ```&``` is achieving that. I think if you want to do that, you'll need to explicitly copy the object using ```angular.copy```. You could do something like:\r\n\r\n```\r\nscope.$watch(scope.data, function (newData, oldData) {\r\n  if (newData !== oldData) {\r\n    chart.update(angular.copy(newData));\r\n  }\r\n}, true);\r\n```\r\n\r\nI do feel like I could be totally missing something here but I'm 99% sure of the way that ```&``` works. It would be great if you could improve my understanding of it a bit if I'm wrong :)"}}