是否可以将我网站上的普通javascript和css函数包含到我的angularjs应用程序中

Is it possible to include normal javascript and css functions from my website into my angularjs app?

本文关键字:包含 函数 css 我的 应用程序 angularjs javascript 网站 是否      更新时间:2024-03-26

我正在用html/css/js开发一个网站,并用angularJS(离子框架)开发其移动应用程序。在我的网站上,我实现了谷歌地理定位和完整日历(http://fullcalendar.io/)。我知道在angularJS中使用,有可用的指令,但由于我很忙,我需要知道我是否可以从我的普通html/css/js网站复制我的完整日历和地理位置Javascript,并将其粘贴到我的angularJS应用程序模板中。如有任何建议,我们将不胜感激。

编辑:

以下是我用于地理位置更新的代码示例。

<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>

这是绝对可能的,您只需要将通常放在bodyhead标记中的所有代码放入角度控制器中。这样,您的控制器将执行您打算在route上执行的任何javascript,或者您在上启动该控制器的任何事件

示例

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
    //    });
  }
}]);

然后,您可以使用正常角度指令执行控制器