Phil 1.5.15

8:00 – 5:30 SR

  • Fix ITK timesheet for 12/21?
  • DB Backups
  • Status report
  • Angular
    • Spent most of the day trying to figure out how to get server information such as referrer. Wound up with a php hack:
// this is the only way that I know to get the referring page. We will then send this to the db.
function getReferrer(){
    $referrer = "No Referrer";
    if(isset($_SERVER['HTTP_REFERER'])) {
        $referrer = htmlentities($_SERVER['HTTP_REFERER']);
        if($referrer == ""){
            $referrer = "No Referrer";
    return $referrer;
echo '<div id="phpReferer" hidden>'.getReferrer().'</div>';
    • This uses php to compile a page with a div named ‘phpReferer’. Since the page exists before Angular has a chance to process it, the hidden div is available in the document. It’s then a matter of getting the $document (passed into the controller) and looking through it. Note that the jQueryLite that angular has doesn’t allow finding divs by ID, so we have to loop over the results for <div> until we find what we’re looking for:
self.phpReferer = null;
var divArray = $document.find('div');
var i;
for(i = 0; i < divArray.length; i++){
   if(divArray[i].id === 'phpReferer'){
      self.phpReferer = divArray[i].innerText;
    • I’m not hugely happy with this, but it does work…
    • Also looked at how to do polymorphism in Angular. I found this example, which is somewhat confusing and bares further examination. The guy who described it, Miško Hevery, is one of the authors of Angular, so I give him the benifit of the doubt. And here’s a talk by him on OO and JavaScript. Currently 46 minutes in.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s