2017-07-19 69 views
0

我想实现openweathermaps api到现有的项目,但我有添加一些依赖关系的问题。openweathermap API角度ES6

当前项目使用ES6(我认为它是Angular的1.5.x版本),我已经通过bower angular-openweathermap-api-factory模块进行安装。

我得到这个错误:ReferenceError:openweathermapFactory没有定义 ,我猜它与“将jtt_openweathermap添加到应用程序的模块依赖关系”有关。因为我不确定如何将其添加到ES6项目。

对此有何帮助?

+0

你能分享你的故障代码的代码片段和完整的错误消息? – itsmichaelwang

+0

实际上,请参阅下面的答案,了解我认为的原因。 – itsmichaelwang

+0

我已经使用http请求并从json中提取数据。它现在有效。如果我有时间,我会尝试在这里使用模块并发布答案来实现它。 – Gifron

回答

1

This tutorial似乎使用相同的API。这是一个reference implementation似乎工作。

看看this file。请注意,作者在第1行中如何将库导入其角度模块中,如jtt_openweathermap?具体的代码行如下所示:

angular.module('myApp', ['ui.router', 'ngGeolocation', 'ngProgress', 'ui.router.title', 'jtt_openweathermap', 'ngMap']) 

您也需要这样做。我想你可能不会那样做。我也会在这里看看controller code,并确保您的导入处理正确。

0

当我添加jtt_openweathermap到控制器的文件,我得到的空白页,没有控制台错误:

angular 
.module('panorama', [ 
    'jtt_openweathermap' 
]) 
.controller('PanoramaCtrl', PanoramaCtrl); 
+0

控制器是否也有天气应用程序的正确导入?看到我发布的控制器代码。天气应用程序有明确的导入。 – itsmichaelwang