Novices start to build angular-cli project


Preface

I have nothing to do to study the angular, if you have any questions, welcome suggestions from the big guys


One, use form components

Need to introduce the formsmodule module in the component module

import {
    
     FormsModule } from '@angular/forms';
@NgModule({
    
    
  declarations: [ ],
  imports: [
    BrowserModule,
    FormsModule,
  ],
  providers: [],
  bootstrap: [AppComponent]
})

2. If you want to use sass

When building the project, you can run the ng new angularDemo01 --style=scss command directly
. Use sass in the case of an existing project
1. Use the cnpm tool to install the sass dependency and loader

cnpm install node-sass --save-dev

cnpm install sass-loader --save-dev

2. Modify the .angular-cli.json file

"styles": [ "styles.scss" ],
"defaults":{
    
     "styleExt": "scss", "component": {
    
    } }

3. Change the styel.css in the project to style.scss

4. Restart the project: ng serve will do

Three, configure routing

import {
    
     Routes, RouterModule } from '@angular/router';
import {
    
     LoginComponent } from './login/login.component';
const routes: Routes = [
  {
    
    
    path: 'loginForm',
    component: LoginComponent
  },
];
@NgModule({
    
    
  declarations: [ ],
  imports: [
    BrowserModule,
    FormsModule,
 RouterModule.forRoot(routes)
  ],
  providers: [],
  bootstrap: [AppComponent]
})

to sum up

A rookie in Angular for the first time, if you find a problem, welcome to advise~~

Guess you like

Origin blog.csdn.net/qq_40969782/article/details/111581987