Angular6項目搭建

參照 草根專欄- ASP.NET Core + Ng6 實戰:https://v.qq.com/x/page/b076702elvw.html
css

安裝工具:

  1. Nodejs, npm     最新版, https://nodejs.org/en/
  2. Angular CLI,    npm install -g @angular/cli
  3. Visual Studio Code,    https://code.visualstudio.com/

Angular Cli

  1. https://github.com/angular/angular-cli
  2. https://cli.angular.io/
  3. ng new
  4. ng generate
  5. ng serve
  6. Test, Lint, Format
  7. 要看文檔!!!

項目搭建

一、在cmd  輸入  ng new blog-client  --style scss  --dry-run   項目建立預覽html

二、在項目目錄下輸入 code .   命令打開vscodenode

三、 安裝 angularMaterial       npm install --save @angular/material @angular/cdk @angular/animations         官網 :https://material.angular.io/guidesgit

四、 在 app.module.ts 中添加github

import {BrowserAnimationsModule} from '@angular/platform-browser/animations';

@NgModule({
  ...
  imports: [BrowserAnimationsModule],
  ...
})
export class PizzaPartyAppModule { }

五、在 app.module.ts 中添加npm

import {MatButtonModule, MatCheckboxModule} from '@angular/material';

@NgModule({
  ...
  imports: [MatButtonModule, MatCheckboxModule],
  ...
})
export class PizzaPartyAppModule { }

六、在scss中添加json

@import "~@angular/material/prebuilt-themes/indigo-pink.css";

七、npm install --save hammerjs      在main.ts 導入bootstrap

import 'hammerjs';

八、 ng g module blog --routing --spec falseapp

九、全局設置 spec爲false,在angular.json中設置ide

        "@schematics/angular:module": {
          "spec": false
        }

十、 ng g module shared/material    將angularMateria組件都導入

十一、將  MaterialModule 導入  blog.module.ts  

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import {MaterialModule} from '../shared/material/material.module'
import { BlogRoutingModule } from './blog-routing.module';

@NgModule({
  imports: [
    CommonModule,
    BlogRoutingModule,
    MaterialModule
  ],
  declarations: []
})
export class BlogModule { }

十二、 ng g component blog/blog-app --flat --inline-style  --inline-template --module blog   建立主組件

1三、配置路由:blog-routing.module.ts

const routes: Routes = [
  {path: '', component: BlogAppComponent}
];

@NgModule({
  imports: [RouterModule.forChild(routes)],
  exports: [RouterModule]
})
export class BlogRoutingModule { }

1三、配置主路由:app.module.ts

const routers: Routes = [
  {path: 'blog', loadChildren: './blog/blog.module#BlogModule'},
  {path: '**' , redirectTo: 'blog' }
];

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule, BrowserAnimationsModule, MatButtonModule, MatCheckboxModule,
    RouterModule.forRoot(routers)
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

1四、配置路由插座:app.component.html

<router-outlet></router-outlet>

1五、ng g c blog/components/sidenav   

1六、ng g c blog/components/toolbar

1七、 導入圖標:blog-app.component.ts

export class BlogAppComponent implements OnInit {
  constructor(iconRegistry: MatIconRegistry, sanitizer: DomSanitizer) {
    iconRegistry.addSvgIcon('baseline-more_vert', sanitizer.bypassSecurityTrustResourceUrl('/assets/baseline-more_vert-24px.svg'));
    iconRegistry.addSvgIcon('baseline-menu', sanitizer.bypassSecurityTrustResourceUrl('/assets/baseline-menu-24px.svg'));
  }
  ngOnInit() {
  }

1八、在app.module.ts 中添加   HttpClientModule

 

圖標下載網站:https://material.io/tools/icons/?icon=more_vert&style=baseline

相關文章
相關標籤/搜索