【问题标题】:openweathermap API to angular ES6openweathermap API 到 Angular ES6
【发布时间】:2017-07-19 12:42:50
【问题描述】:

我想为现有项目实现 openweathermaps api,但在添加一些依赖项时遇到问题。

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

我收到此错误:ReferenceError: openweathermapFactory is not defined 我猜它与“将 jtt_openweathermap 添加到应用程序的模块依赖项”有关。因为我不确定如何将它添加到 ES6 项目中。

有什么帮助吗?

【问题讨论】:

  • 您能分享您的故障代码的代码 sn-p 和完整的错误消息吗?
  • 实际上,我的答案见下文。
  • 我使用了 http 请求并从 json 中提取数据。现在可以了。如果我有时间,我会尝试使用模块来实现它并在此处发布答案。

标签: javascript angularjs ecmascript-6


【解决方案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,并确保您的导入也得到正确处理。

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

    • 控制器是否也有天气应用程序的正确导入?请参阅我发布的控制器代码。天气应用程序有一个明确的导入。
    猜你喜欢
    • 2020-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-04
    • 2017-04-14
    • 2018-06-05
    • 2021-12-31
    • 2020-11-15
    相关资源
    最近更新 更多