You're mixing the presentation and data layer here. Instead the presentation code should live in a directive, like the [forceDirectedGraph](https://github.com/Lab41/Dendrite/blob/master/src/main/webapp/js/directives.js#L93).