REQUEST A DEMO

Tag: AngularJS

Organizing your Angular App with Constants

June 27, 2014 Often times we find ourselves coding strings into our javascript that when seriously thought through, should have been constants. One good example I found in my own code was a factory that sends statistics down to our server. The factory was coded to take in a topic along with the action performed. This is all good, the issue was in the controllers sending the data into the factory. I found I was sending hard coded strings which didn't sit well with me. An example of this would look like: $scope.linkClickedStat = function(linkLocation) { statFactory.sendStat('LinkClicked', linkLocation); } The first part of the signature as you can see I am sending a hard coded string of LinkClicked. How can this be a problem later? Well, a couple of issues here. I could misspell this in another controller and our stats will be…