ng serve每次对源文件进行任何更改时都需要运行.我在控制台中没有错误.
Angular CLI: 1.6.2
Node: 8.9.1
OS: linux ia32
Angular: 5.1.2
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router
@angular/cdk: 5.0.2-c3d7cd9
@angular/cli: 1.6.2
@angular/material: 5.0.3-e20d8f0
@angular-devkit/build-optimizer: 0.0.36
@angular-devkit/core: 0.0.22
@angular-devkit/schematics: 0.0.42
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.9.2
@schematics/angular: 0.1.11
@schematics/schematics: 0.0.11
typescript: 2.4.2
webpack: 3.10.0
pla*_*ter 111
你试过ng serve --watch吗?
在Linux中也是大部分时间,ng build --watch或者sudo如果目录没有足够的权限则不起作用.
解决方案是提供必要的权限或使用   ng serve.
UPDATE
watch flag in ng serve --watch实际上是多余的,因为它是默认选项.感谢@Zaphoid指出错误.
小智 87
ng serve --poll=2000
在linux和windows中工作正常
Muh*_*bba 52
考虑到,当拥有大量文件时,Linux 上的INotify手表有一个限制.因此,例如,将手表限制增加到512K可以解决这个问题.
sudo sysctl fs.inotify.max_user_watches=524288
sudo sysctl -p --system
请注意,前一个导致内存中的更改,您将在重新启动后丢失.
但是,您可以通过执行以下命令使其持久化:
echo fs.inotify.max_user_watches=524288 | sudo tee /etc/sysctl.d/40-max-user-watches.conf && sudo sysctl --system
作为参考,您可以查看:https://github.com/angular/angular-cli/issues/8313#issuecomment-362728855和 https://github.com/guard/listen/wiki/Increasing-the-amount-的-的inotify观察家
chi*_*iya 22
因为,默认情况下,检测到更改的系统无法处理如此多的手表.
解决方案是change the amount of watches它可以处理(项目中最大的文件数量),您必须run this command:
echo 65536 | sudo tee -a /proc/sys/fs/inotify/max_user_watches
每次重新启动计算机时,inotify的问题都会重置此计数器.
小智 13
在您的项目中dist文件夹由root拥有
尝试使用sudo ng serve代替ng serve。
另一种解决方案
当有大量文件时,监视在Linux中不起作用.Linux上的INotify监视有一个限制。所以增加手表的极限
//When live server not work in linux
sudo sysctl fs.inotify.max_user_watches=524288
sudo sysctl -p --system
ng serve //You can also do sudo **ng serve**
小智 5
如果这与我遇到的问题相同,则可能会有所帮助。尝试使用ng serve和ng build --watch有时的工作,但他们大多不看代码的变化,我认为这是事做ng。
然后我想起了我以前用inotify手表遇到的一个问题
我在Ubuntu机器上运行了它,似乎已经启动并观看了代码更改:
回声fs.inotify.max_user_watches = 524288 | 须藤tee /etc/sysctl.d/40-max-user-watches.conf &&须藤sysctl --system
归功于Scott Smith