【问题标题】:cannot inject falcor in angular app无法在 Angular 应用程序中注入 falcor
【发布时间】:2016-07-07 03:57:57
【问题描述】:

我在我的 Angular 应用程序中使用 browserify。我阅读了一些关于 falcor 的文章并决定进行测试,但在我的应用程序中注入它时遇到问题。所以我通过 npm 安装了 falcor,我试图像这样注入它:

require('falcor');

var app = angular.module('app', ['ui.router', 'login', 'falcor'];

但我收到:Failed to instantiate module falcor due to 错误。

以后在我的服务中,我的想法是做这样的事情:

app.service('loginService', function(falcor) {
  function falcor() {
        var model = new falcor.Model({
            cache: {
                events: [
                    {
                        name: "ng-conf",
                        description: "The worlds best Angular Conference",
                        location: { city: "Salt Lake City", state: "Utah" }
                    },
                    {
                        name: "NodeConf",
                        description: "NodeConf is the longest running community driven conference for the Node community.",
                        location: { city: "Walker Creek Ranch", state: "California" }
                    }

                ]
            }
        });

        model
        // We want the name and description values for the first three items
        // from the data model
            .get(["events", {from: 0, to: 2}, ["name", "description"]])
            .then(function(response) {

            });
    }

     return {
          falcor: falcor
     }
});

所以我的问题是如何正确注入 falcor 以便我可以在我的应用程序中使用它?几乎没有关于使用 angular 和 falcor 的例子,所以我很困惑。

我找到了一个 npm 包 - ng-falcor,但由于没有示例,只有一些关于 api 的基本描述,我决定跳过它。

【问题讨论】:

    标签: angularjs falcor


    【解决方案1】:

    falcor 库不包含名为 falcor 的 Angular 模块。从模块的依赖项中删除它:angular.module('app', ['ui.router', 'login'];。这不会阻止您使用falcor 全局。

    【讨论】:

      【解决方案2】:

      它没有找到模块'falcor'的原因是因为你没有给脚本去......所以在你的index.html文件中添加这个:

      <script src="https://netflix.github.io/falcor/build/falcor.browser.js"></script>
      

      那么现在当你运行它时,它知道 falcor 是什么,所以它可以运行它!希望这有帮助!

      【讨论】:

      • 我不需要在我的 index.html 文件中包含对 falcor 的引用。我已经用 npm 安装了 falcor,它在我的 node_packages 中。如示例中所述,我通过 require('falcor') 语句加载它。
      猜你喜欢
      • 2023-03-27
      • 1970-01-01
      • 2014-07-31
      • 1970-01-01
      • 2016-11-29
      • 2018-09-22
      • 2018-10-27
      • 1970-01-01
      • 2016-01-18
      相关资源
      最近更新 更多