2017-07-19 72 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