当我在CLI上运行ng serve
时,得到以下输出:
Angular Live Development Server正在侦听localhost:4200,请打开浏览器,网址为http://localhost:4200/
但是当我在浏览器中打开http://localhost:4200/时,什么也没有。
对于如何解决这个问题有什么建议吗?
这是我的package.json
{
"name": "eastlaw",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "^6.1.0",
"@angular/common": "^6.1.0",
"@angular/compiler": "^6.1.0",
"@angular/core": "^6.1.0",
"@angular/forms": "^6.1.0",
"@angular/http": "^6.1.0",
"@angular/platform-browser": "^6.1.0",
"@angular/platform-browser-dynamic": "^6.1.0",
"@angular/router": "^6.1.0",
"core-js": "^2.5.4",
"rxjs": "6.0.0",
"zone.js": "~0.8.26"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.7.0",
"@angular/cli": "~6.1.5",
"@angular/compiler-cli": "^6.1.0",
"@angular/language-service": "^6.1.0",
"@types/jasmine": "~2.8.6",
"@types/jasminewd2": "~2.0.3",
"@types/node": "~8.9.4",
"codelyzer": "~4.2.1",
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~1.7.1",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.0",
"karma-jasmine": "~1.1.1",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.4.0",
"ts-node": "~5.0.1",
"tslint": "~5.9.1",
"typescript": "~2.7.2"
}
}
4条答案
按热度按时间bq8i3lrv1#
要调试此问题,请尝试以下操作:
如果可能,尝试上载浏览器控制台映像
anhgbhbe2#
请考虑以下几点:
1.通过
ng serve
打开服务器,它只能在该设备上的浏览器上打开。1.如果要为网络上的设备提供此服务,则应使用
ng serve -- host <your_device_ip>
注:设备IP是您从中提供服务的设备的IP地址。
kkbh8khc3#
首先,验证计算机的IP地址。
在Windows上,在提示符中键入
ipconfig
(复制IPv4)。在Mac上,在终端中键入ifconfig |grep inet
(复制inet)。在我的例子中,这是192.168.0.10。接下来,键入命令
ng serve --host 192.168.0.10
Ok,您的应用程序对同一网络上的所有设备进行空中传输。现在只有
http://192.168.0.10:4200/
可以工作,localhost不能。v440hwme4#
有两种解决方案。步骤1 -在项目启动时键入ng serve --port 4300步骤2-angular.json文件中需要更改的区域如下所示。