logo

How to make Connecto work with Angular based web app?

What it does:

Lets you integrate connecto into an angularjs based web app. Our original snippet can be used with small changes to work in Angular, the reason why connecto doesn’t work in angular is,

The snippet only makes a call to the server once and whatever is the state of the page, determines the notifications returned. In Angular, page is loaded only once and the rest of the changes are ajax or local Js driver.

In order to fix this, we can make the call to the server on every angular controller view.

How to set up:

1.After you get the snippet from our website do the following steps:

  • In the base page of your angular module, Initialize _TConnecto once:
    var _TConnecto = _TConnecto || {};
    _TConnecto.licenseKey = ‘XXXXXX';    (in the place of ‘XXXXXX’ , your licence Key should be present.)
  1. Now in every other controller of your module, we have to call the rest of the connecto snippet, which can be done as:
  • function callConnecto() {
     _TConnecto.initPage();
    (function() {
    var con = document.createElement(‘script’); con.type = ‘text/javascript';
    var host = (document.location.protocol === ‘http:’) ? ‘http://cdn’ : ‘https://server';
    con.src = host + ‘.connecto.io/javascripts/connect.prod.min.js';
    var s = document.getElementsByTagName(‘script’)[0];
    s.parentNode.insertBefore(con, s);
    })();
    }
    callConnecto();

The above step is done so as to give the server call everytime there is a controller view occuring, and the “ _TConnecto.initPage()”  is called upon everytime to reinstate the local variables created in DOM and the setTimeout events that we may have created.

0 found this helpful