新建angular工程

一 本地创建angular工程

多看官网文档 https://angular.cn/guide/setup-local

 1本地安装angular-cli

npm install -g @angular/cli

2 新建工程

ng new my-app

选择使用路由,选择css

 

新的ng7/8 直接把路由模块app-routing.module.ts给创建好了,比文档里讲的还方便。包括在app.component.html下连

<router-outlet></router-outlet>都添加好了

全家桶就是这么霸气 233

 

此时,已经可以运行

3 配置angular.json

3.1使用bootstrap

安装bootstrap

npm i bootstrap

 

安装material
ng add @angular/material

 

 

设置angular.json

      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist/package.nw",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.app.json",
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "./node_modules/bootstrap/dist/css/bootstrap.min.css",
              "./node_modules/@angular/material/prebuilt-themes/pink-bluegrey.css",
              "src/styles.css"
            ],

 

配置 tsconfig.json

{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "noImplicitAny": false,
    "suppressImplicitAnyIndexErrors": true,
      "strictNullChecks": false,
"strict": true,
......

增加这2行,防止声明member的时候必须写明any,否则报错

 删除 src/index.html里这3行,防止内网每次下载字体特别慢

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>TdpAdmin</title>
  <base href="/">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="icon" type="image/x-icon" href="favicon.ico">
  <link rel="preconnect" href="https://fonts.gstatic.com">
  <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500&display=swap" rel="stylesheet">
  <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
</head>
<body>
  <app-root></app-root>
</body>
</html>

 

 

清空src/app/app.component.html

现在的angular的这个里面塞了大量的东西,统统删掉,搞成这样

<p>启动成功</p>
<router-outlet></router-outlet>

二 远程仓库创建,关联

步骤一:切换到您的仓库的目录

cd /path/to/your/repo

步骤二:连接您的现有仓库与 Bitbucket

git remote add origin git@bitbucket.org:XXX/YYY.git
git push -u origin master

 

感言:

 

确实,ng类似java, 很多废话,一定要把一个简单的动词(get)封装到1个名词上(XXXService).

这种强制一切都是对象的,过度OOP,确实有点烦人。

但是,ng是全家桶的框架,意义在于:当前端不是我的核心域的时候,我不会为了获得90%的爽,而被10%的不爽卡死。去精细定制router 状态管理等等等各种东西

为此,宁可稍微容忍这种不爽。 反正业务代码都在service里

其实倒未必有多解耦,只是撸得相对无脑,肯定不如函数式精炼。

posted @ 2019-03-17 15:37  永远的幻想  阅读(343)  评论(0编辑  收藏  举报