当我在请求数据时返回简单的 JSON 而没有连接到数据库时,Angular Universal 中的服务器渲染工作正常.
When in my requests for data I return simple JSON without connection to database the server rendering in Angular Universal works fine.
然而,我发现如果我没有正确版本的 Zone.js,对 MySQL 数据库的请求将不会进行.我有以下错误:
However I have found that requests to MySQL database is not going if I don't have a proper version of Zone.js. I had the following error:
TypeError: Cannot read property 'on' of undefined
at Protocol._enqueue (/Applications/MAMP/htdocs/Angular2/myproject/node_modules/mysql/lib/protocol/Protocol.js:152:5)
...
我还注意到我有一个警告:
Also I payed attention that I had a warning:
angular2-universal@2.1.0-rc.1 requires a peer of zone.js@~0.6.21 but none was installed.
所以我安装了正确的 Zone.js:
So I installed proper Zone.js:
npm install zone.js@0.6.21
然后我开始从 MySQL 接收数据.
and I started receiving data from MySQL.
但是!此时服务器渲染停止工作!我只看到:
BUT! At this point server rendering stops working! I only see:
<!--template bindings={}-->
在 HTML 模板中.
in HTML-template.
我返回一个没有连接到 MySQL 的 JSON,发现即使在这种情况下服务器渲染也不起作用.
I moved back to return a JSON without connection to MySQL and have found that even at this case server rendering is not working.
所以我玩了一点,发现如果我使用命令:
So I have played a little with this and have found that if I use command:
npm install zone.js
然后当我在没有连接到数据库的情况下返回 JSON 时,服务器渲染正常工作,但是如果我尝试连接到 MySQL,则会发生原始错误.
then server rendering works properly when I return JSON without connection to database, but if I try to connect to MySQL then original error occurs.
所以现在我可以在没有服务器渲染的情况下使用工作服务器渲染或连接到 MySQL.不是服务器渲染和与数据库的工作连接.
So now I have either working server rendering or connection to MySQL without server rendering. Not server rendering and working connection to database.
如果有人知道应该做什么,我将不胜感激.谢谢你.
If anyone knows what should be done I'll appreciate the help. Thank you.
我找到了解决方案.就我而言,问题已通过以下命令解决:
I have found the solution. In my case the issue was resolved by the command:
npm install zone.js@latest
现在我可以向 MySQL 发出请求,而且我有一个服务器渲染,可以看到我的 HTML 模板中的所有数据.
Now I can do the requests to MySQL and also I have a server rendering and can see all the data in my HTML-template.
这篇关于由于 Angular Universal 服务器渲染中的 Zone.js 停止工作.怎么修?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
获取所有产品、类别和元数据的 SQL 查询 woocommSQL query to get all products, categories and meta data woocommerce/wordpress(获取所有产品、类别和元数据的 SQL 查询 woocommerce/wordpre
如何在 WSL(Linux 的 Windows 子系统)中使用 MySQL?How to use MySQL in WSL (Windows Subsystem for Linux)?(如何在 WSL(Linux 的 Windows 子系统)中使用 MySQL?)
任务计划程序中的 PowerShell MySQL 备份脚本错误 PowerShell MySQL Backup Script Error in Task Scheduler 0x00041301(任务计划程序中的 PowerShell MySQL 备份脚本错误 0x00041301)
将数据从 XML 文件导入 MySQL 数据库Import the data from the XML files into a MySQL database(将数据从 XML 文件导入 MySQL 数据库)
在 Windows 7 32 位上安装 Xampp.启动时的错误installed Xampp on Windows 7 32-bit. Errors when starting(在 Windows 7 32 位上安装 Xampp.启动时的错误)
Windows xampp 上的 Mysql 小写表Mysql lower case table on Windows xampp(Windows xampp 上的 Mysql 小写表)