0

I am developing a website in html/css/js and its mobile application in angularJS (ionic framework). In my website I have implemented google geolocation and full calendar(http://fullcalendar.io/). I know that for use in angularJS, there are directives available but since I am in hurry, i need to know that is it possible that I copy over my fullcalendar and geolocation Javascript from my normal html/css/js website and paste it in my template of angularJS app. Any suggestions will be highly appreciated.

EDIT:

Here is example of code I am using for geolocation updating.

<script>
        if ("geolocation" in navigator) 
    {
        request_location();
    } 

    // Requesting location from user
    function request_location()
    {
        // Will repeat the process in two minutes
        setTimeout(request_location, 1000*60*2);

        // Get location info from browser and pass it to updating function
        navigator.geolocation.getCurrentPosition(update_location);
    }

    // Sending location to server via POST request
    function update_location(position)
    {
        // For simplicity of example we'll 
        // send POST AJAX request with jQuery
        $.post( "functions.php?action=update_geolocation", { latitude: position.coords.latitude, longitude: position.coords.longitude });
        //$.post("functions.php?action=update_geolocation&latitude="+ position.coords.latitude + '&longitude=' + position.coords.longitude,
       /* {
            latitude : position.coords.latitude,
            longtitude : position.coords.longitude
        },*/
    //    function(){
    //        // Position sent, may update the map
    //    });
    }

        </script>
Dasmond Miles
  • 183
  • 2
  • 10
  • 1
    This question is a bit too broad to just offer a definite answer. It is definitely possible for JQuery plugins like fullcalendar to co-exist with angular, but there can be timing issues and it would not be possible to know for certain if these would affect you without some example of your current use scenario in code. – Claies Apr 10 '16 at 00:34
  • @Claies I have included an example of my code in the edit, If you want to have a look at my fullcalendar code, i can post that here also, its a bit long though – Dasmond Miles Apr 10 '16 at 01:17
  • It is definitely possible. But that's a bad practice. Because whatever you have to do in angular should be done in a proper way. Not as a standalone code. – SuperNova Apr 10 '16 at 06:48

1 Answers1

1

It is definitely possible, you just need to put all of your code that you would normally put anywhere in your body or head tags into angular controllers. This way your controller will execute any javascript you intend to execute on that route or whatever event you fire that controller on

example

myApp.controller('exampleController', ['$scope', function($scope) {
  if ("geolocation" in navigator) {
    request_location();
  }

  // Requesting location from user
  function request_location() {
    // Will repeat the process in two minutes
    setTimeout(request_location, 1000 * 60 * 2);

    // Get location info from browser and pass it to updating function
    navigator.geolocation.getCurrentPosition(update_location);
  }

  // Sending location to server via POST request
  function update_location(position) {
    // For simplicity of example we'll 
    // send POST AJAX request with jQuery
    $.post("functions.php?action=update_geolocation", {
      latitude: position.coords.latitude,
      longitude: position.coords.longitude
    });
    //$.post("functions.php?action=update_geolocation&latitude="+ position.coords.latitude + '&longitude=' + position.coords.longitude,
    /* {
         latitude : position.coords.latitude,
         longtitude : position.coords.longitude
     },*/
    //    function(){
    //        // Position sent, may update the map
    //    });
  }
}]);

Then you can execute the controller using normal angular directives

Rohit Agre
  • 1,528
  • 1
  • 14
  • 25
  • Arge , Why can I not put it simply in –  Apr 17 '16 at 09:36
  • You can definitely do that, but when you change pages via angular, your functions will be registered again and they will be called multiple times – Rohit Agre Apr 18 '16 at 07:48