1.快速安装node
cnpm install -g @angular/cli
2.建立一个带路由的新项目npm
ng new peoject_name --routing(project_name为项目名称)
3.运行项目(百度有些案例说直接输入命令“ng serve”便可启动项目,可是我电脑的项目不知道为何不行,因此只能使用下面这行命令)json
ng serve --open
使用 –open(或-o) 参数能够自动打开浏览器并访问http://localhost:4200/浏览器
Angular-cli修改端口app
经过命令行方式修改:spa
ng serve --port 端口号
修改端口号还能够经过另外一种方法:(可是个人项目找不到这个文件,因此我只能经过命令修改端口号)命令行
找到node_modules/angular-cli/lib/config/schema.json
default值就是默认的端口code
"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"
}
}
}
}
这是启动后的页面:blog