احراز هویت و اعتبارسنجی کاربران در برنامههای Angular - قسمت اول - معرفی و ایجاد ساختار برنامه
نویسنده: وحید نصیری
تاریخ: ۱۳۹۶/۰۹/۲۵ ۱۴:۱۵
آدرس: www.dntips.ir
| مطالب | ۳۶۹۴ |
| نویسندگان | ۲۷۶ |
| گروههای مطالب | ۱۰۲۴ |
| نقشههای راه | ۱۱۹ |
| دورهها | ۱۴ |
| اشتراکها | ۱۷۹۱۴ |
> ng new ASPNETCore2JwtAuthentication.AngularClient --routing
> npm install bootstrap --save
"apps": [
{
"styles": [
"../node_modules/bootstrap/dist/css/bootstrap.min.css",
"styles.css"
], >ng g c welcome >ng g c PageNotFound
@NgModule({
declarations: [
AppComponent,
WelcomeComponent,
PageNotFoundComponent
], import { PageNotFoundComponent } from './page-not-found/page-not-found.component';
import { WelcomeComponent } from './welcome/welcome.component';
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
const routes: Routes = [
{ path: 'welcome', component: WelcomeComponent },
{ path: '', redirectTo: 'welcome', pathMatch: 'full' },
{ path: '**', component: PageNotFoundComponent }
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { } >ng g m Authentication -m app.module --routing
create src/app/authentication/authentication-routing.module.ts (257 bytes) create src/app/authentication/authentication.module.ts (311 bytes) update src/app/app.module.ts (696 bytes)
import { EmployeeRoutingModule } from './employee/employee-routing.module';
@NgModule({
imports: [
BrowserModule,
AppRoutingModule,
AuthenticationModule
] import { EmployeeModule } from './employee/employee.module';
@NgModule({
imports: [
BrowserModule,
AuthenticationModule,
AppRoutingModule
] >ng g c Authentication/Login
create src/app/Authentication/login/login.component.html (24 bytes) create src/app/Authentication/login/login.component.ts (265 bytes) create src/app/Authentication/login/login.component.css (0 bytes) update src/app/Authentication/authentication.module.ts (383 bytes)
import { LoginComponent } from "./login/login.component";
@NgModule({
declarations: [LoginComponent]
}) import { LoginComponent } from "./login/login.component";
const routes: Routes = [
{ path: "login", component: LoginComponent }
]; import { NgModule, SkipSelf, Optional, } from "@angular/core";
import { CommonModule } from "@angular/common";
import { RouterModule } from "@angular/router";
// import RxJs needed operators only once
import "./services/rxjs-operators";
import { BrowserStorageService } from "./browser-storage.service";
@NgModule({
imports: [CommonModule, RouterModule],
exports: [
// components that are used in app.component.ts will be listed here.
],
declarations: [
// components that are used in app.component.ts will be listed here.
],
providers: [
// global singleton services of the whole app will be listed here.
BrowserStorageService
]
})
export class CoreModule {
constructor( @Optional() @SkipSelf() core: CoreModule) {
if (core) {
throw new Error("CoreModule should be imported ONLY in AppModule.");
}
}
} import { NgModule, ModuleWithProviders } from "@angular/core";
import { CommonModule } from "@angular/common";
@NgModule({
imports: [
CommonModule
],
entryComponents: [
// All components about to be loaded "dynamically" need to be declared in the entryComponents section.
],
declarations: [
// common and shared components/directives/pipes between more than one module and components will be listed here.
],
exports: [
// common and shared components/directives/pipes between more than one module and components will be listed here.
CommonModule
]
/* No providers here! Since they’ll be already provided in AppModule. */
})
export class SharedModule {
static forRoot(): ModuleWithProviders {
// Forcing the whole app to use the returned providers from the AppModule only.
return {
ngModule: SharedModule,
providers: [ /* All of your services here. It will hold the services needed by `itself`. */]
};
}
} import { FormsModule } from "@angular/forms";
import { HttpClientModule } from "@angular/common/http";
import { CoreModule } from "./core/core.module";
import { SharedModule } from "./shared/shared.module";
@NgModule({
imports: [
BrowserModule,
FormsModule,
HttpClientModule,
CoreModule,
SharedModule.forRoot(),
AuthenticationModule,
AppRoutingModule
]
})
export class AppModule { } > ng g c Header
create src/app/header/header.component.html (25 bytes) create src/app/header/header.component.ts (269 bytes) create src/app/header/header.component.css (0 bytes) update src/app/app.module.ts (1069 bytes)
<nav>
<div>
<div>
<a [routerLink]="['/']">{{title}}</a>
</div>
<ul>
<li role="menuitem" routerLinkActive="active" [routerLinkActiveOptions]="{ exact: true }">
<a [routerLink]="['/welcome']">Home</a>
</li>
<li role="menuitem" routerLinkActive="active">
<a queryParamsHandling="merge" [routerLink]="['/login']">Login</a>
</li>
</ul>
</div>
</nav> export class HeaderComponent implements OnInit {
title = "Angular.Jwt.Core"; <app-header></app-header> <div> <router-outlet></router-outlet> </div>
import { HeaderComponent } from "./component/header/header.component";
@NgModule({
exports: [
// components that are used in app.component.ts will be listed here.
HeaderComponent
],
declarations: [
// components that are used in app.component.ts will be listed here.
HeaderComponent
]
})
export class CoreModule { dotnet new angular --auth Individual
dotnet new react --auth Individual //or dotnet new reactredux --auth Individual