1.快速安装
cnpm install -g @angular/cli
2.创建一个带路由的新项目
ng new peoject_name --routing(project_name为项目名称)
3.运行项目(百度有些案例说直接输入命令“ng serve”即可启动项目,但是我电脑的项目不知道为什么不行,所以只能使用下面这行命令)
ng serve --open
使用 –open(或-o) 参数可以自动打开浏览器并访问http://localhost:4200/
Angular-cli修改端口
通过命令行方式修改:
ng serve --port 端口号
修改端口号还可以通过另一种方法:(但是我的项目找不到这个文件,所以我只能通过命令修改端口号)
找到node_modules/angular-cli/lib/config/schema.json
default值就是默认的端口
"serve": {
"description": "Properties to be passed to the serve command",
"type": "object",
"properties": {
"port": {
"description": "The port the application will be served on",
"type": "number",
"default": 4200
},
"host": {
"description": "The host the application will be served on",
"type": "string",
"default": "localhost"
}
}
}
}
这是启动后的页面: