【问题标题】:Error: "app" did not match any elements错误:“app”不匹配任何元素
【发布时间】:2016-12-30 17:11:07
【问题描述】:

我正在创建一个带有node.js 服务器的angular2 客户端应用程序。客户端应用程序似乎工作得很好,这意味着:

  • 我的所有请求都得到了适当的响应。
  • 应用程序按预期加载和工作。

但我在终端收到此错误:

Error: The selector "app" did not match any elements
    at DomRenderer.selectRootElement (/home/mu-user/Projects/my-app/dist/server/index.js:27126:23)
    at selectOrCreateRenderHostElement (/home/mu-user/Projects/my-app/dist/server/index.js:15687:32)
    at AppView._View_AppComponent_Host0.createInternal (/AppModule/AppComponent/host.ngfactory.js:12:16)
    at AppView.create (/home/mu-user/Projects/my-app/dist/server/index.js:50916:21)
    at ComponentFactory.create (/home/mu-user/Projects/my-app/dist/server/index.js:36656:36)
    at ApplicationRef_.bootstrap (/home/mu-user/Projects/my-app/dist/server/index.js:23313:40)
    at /home/mu-user/Projects/my-app/dist/server/index.js:23222:89
    at Array.forEach (native)
    at Object.Call (/home/mu-user/Projects/my-app/node_modules/es6-shim/es6-shim.js:307:14)
    at Array.forEach (/home/mu-user/Projects/my-app/node_modules/es6-shim/es6-shim.js:1313:17)

不会中断webpackhttp-server
问题是我为什么要面对这个问题以及如何解决它?

【问题讨论】:

  • 你能包含一些你的主要文件吗?像 index.html、引导文件、模块..
  • 这很可能是某种与 ngModule 相关的问题,因为您的应用不了解主要组件。您需要向我们展示一些我们可以提供帮助的代码
  • @echonax 这个项目包含 50 多个组件,几乎不可能添加整个代码,但是恢复到较旧的提交以获得更简单的版本,我注意到错误消失了。所以也没有用。
  • @JoshuaOhana 我使用了一个较旧的提交来展示一个更简单的版本,我注意到它正在工作。这是发现你是对的关键。你认为这个错误是一种“未处理”还是它实际上是为了显示“找不到应用程序元素”?除非你说,否则我无法理解其含义

标签: angular angular-universal


【解决方案1】:

正如我在 cmets 中所描述的那样,我正在添加这个答案以供记录。此错误已通过修复对 ngModule 声明列表中包含的模块的引用得到解决。
从错误消息的上下文中找出问题是很棘手的。而且由于代码的复杂性,不可能包含实际的项目代码,但我在尝试制作一个更简单的版本时发现了这个问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-05-26
    • 2016-06-09
    • 1970-01-01
    • 2016-06-09
    • 1970-01-01
    • 1970-01-01
    • 2016-11-24
    相关资源
    最近更新 更多