是否可以将我网站上的普通javascript和css函数包含到我的angularjs应用程序中
Is it possible to include normal javascript and css functions from my website into my angularjs app?
我正在用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>
这是绝对可能的,您只需要将通常放在body
或head
标记中的所有代码放入角度控制器中。这样,您的控制器将执行您打算在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
// });
}
}]);
然后,您可以使用正常角度指令执行控制器
相关文章:
- 此行是否包含函数声明
- JavaScript 自包含函数数组访问自我索引
- 包含函数的JSON
- 如何在事件处理程序中包含函数(及其参数),而不在页面加载时调用该函数
- 包含函数调用的json字符串
- 如何解析包含函数的 JSON 字符串
- 何时使用自包含函数(闭包),何时不使用自包含函数
- 如何制作自包含函数
- 如何在包含函数的方法中使用类变量
- 如何让我的包含函数工作
- 最好导出一个包含函数的对象,或者只导出ES6中的多个函数(有约定吗?)
- 一个简单窗口的计算资源密集度.包含函数
- 变量中包含函数的变量
- 如何执行包含函数名和参数的字符串
- 是否可以包含函数作为javascript构造函数参数
- 包含函数的对象文字表示法的执行速度是否比(全局范围)普通函数(取消引用)更快
- 参数包含函数中的表达式
- 如何在 JavaScript 中使用 reduce 而不是 for 循环构建包含函数
- Javascript,检查数组是否包含函数
- 当选择标签包含函数时,选择默认选项