我尝试了两种AngularDART路线,以及使用Polymer this example
的路线但是发现,一旦我直接从Dartium打开文件,没有一个工作,但是一旦我从Dart编辑器运行它们,它们都能正常工作!
我正在做错事!感谢
答案 0 :(得分:1)
这是因为当您从DartEditor(Ctrl + R)运行时,pub serve
被启动,充当浏览器的Web服务器。这并不意味着你需要一个Web服务器来运行这个例子
差异在于pub serve
运行变换器,当浏览器从服务器请求页面时,它会动态地进行某些代码修改。
当您运行pub build
(或代码不在pub build example
目录中时为web
)时,会应用此代码修改(以及更像树木抖动和缩小功能),您可以在没有使用文件URL的服务器的情况下直接打开结果输出(来自build/example/example_01.html
)。
答案 1 :(得分:0)
我认为重点是使用" import html"文件,可以与网络服务器和一些浏览器一起运行,例如路线在没有网络服务器的Safari浏览器上顺利运行,但是在Chrome没有服务器时没有运行,Chrome显示此错误信息:
Imported resource from origin 'file://' has been blocked from loading by
Cross-Origin Resource Sharing policy: Received an invalid response. Origin 'null'
is therefore not allowed access.