Angular Taskmgr 登录
一、登录module
1、先创建domain文件夹,在里面建一个user.model.ts的user领域对象。
export interface User{
id?:string;
email:string;
password:string;
name:string;
avatar:string;
}
2、ng g m login创建一个login module.
在login下创建一个login组件。
3、在login下建立一个login-routing.module.ts子路由。
【最好为每个模块建立自己的路由】
建立路由的快捷方式。装插件Angulae7 Snippets,用ng-router-featuremodule.

import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { CommonModule } from '@angular/common';
import { LoginComponent } from './login/login.component';
import { RegisterComponent } from './register/register.component';
const routes: Routes = [
{ path: '', component: LoginComponent },
{ path: 'register', component: RegisterComponent }
];
@NgModule({
imports: [CommonModule, RouterModule.forChild(routes)],
exports: [RouterModule]
})
export class LoginRoutingModule {}
4、配置根路由
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
const routes: Routes = [
{
path: '', redirectTo: '/login', pathMatch: 'full'
},
{
path:'login',loadChildren:'./login/login.module#LoginModule'
}
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
确保根模块中引入根路由。
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { CoreModule } from './core/core.module';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { MatSidenavModule} from '@angular/material';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
BrowserAnimationsModule,
AppRoutingModule,
CoreModule,
MatSidenavModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
子模块导入子路由。
import { NgModule } from '@angular/core';
import { LoginComponent } from './login/login.component';
import { SharedModule } from '../shared/shared.module';
import { LoginRoutingModule } from './login-routing.module';
@NgModule({
declarations: [LoginComponent],
imports: [
SharedModule,
LoginRoutingModule
]
})
export class LoginModule { }
5、安装animation动画依赖
npm install --save @angular/animations
6、布局
<form>
<mat-card class="example-card">
<mat-card-header>
<mat-card-title>登录:</mat-card-title>
</mat-card-header>
<mat-card-content>
<mat-form-field class="example-full-width" class="full-width">
<input type="text" matInput placeholder="您的email" style="text-align: right">
</mat-form-field>
<mat-form-field class="example-full-width" class="full-width">
<input type="password" matInput placeholder="您的密码" style="text-align: right">
</mat-form-field>
<button mat-raised-button type="button">登录</button> </mat-card-content>
<mat-card-actions class="text-right">
<p>还没有账户?<a href="">注册</a></p>
<p>忘记密码?<a href="">找回</a></p>
</mat-card-actions>
</mat-card>
</form>
form {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
width: 100%;
height: 100%;
}
mat-card {
width: 20em;
margin: 5px;
flex: 0 0 20em;
}
.full-width {
width: 100%;
}
.text-right {
margin: 10px;
text-align: end;
}

二、register Component
1、在login下面新建register组件
ng g c login/register
2、注册组件头像模块使用svg
在之前文章介绍过matIcon中可以使用svg做为资源。
通过addSvgIconSetInNamespace来添加图标集
import { MatIconRegistry } from "@angular/material";
import { DomSanitizer } from "@angular/platform-browser";
export const loadSvgResources = (ir: MatIconRegistry, ds: DomSanitizer) => {
const imgDir = "assets/img";
const avatarDir = `${imgDir}/avatar`;
const sidebarDir = `${imgDir}/sidebar`;
const dayDir = `${imgDir}/days`;
ir.addSvgIconSetInNamespace( //通过addSvgIconSetInNamespace来添加图标集
"avatars",
ds.bypassSecurityTrustResourceUrl(`${avatarDir}/avatars.svg`)
);
ir.addSvgIcon(
"day",
ds.bypassSecurityTrustResourceUrl(`${sidebarDir}/day.svg`)
);
ir.addSvgIcon(
"month",
ds.bypassSecurityTrustResourceUrl(`${sidebarDir}/month.svg`)
);
ir.addSvgIcon(
"project",
ds.bypassSecurityTrustResourceUrl(`${sidebarDir}/project.svg`)
);
ir.addSvgIcon(
"projects",
ds.bypassSecurityTrustResourceUrl(`${sidebarDir}/projects.svg`)
);
ir.addSvgIcon(
"week",
ds.bypassSecurityTrustResourceUrl(`${sidebarDir}/week.svg`)
);
const days =[,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,];
days.forEach((d)=>{
ir.addSvgIcon(
`day${d}`,
ds.bypassSecurityTrustResourceUrl(`${dayDir}/day${d}.svg`)
);
});
};
在注册页面中
ngOnInit() {
const nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16];
this.items = nums.map(d => `avatars:svg-${d}`);
}
在模版中
<mat-grid-list cols="8">
<mat-grid-tile *ngFor="let item of items">
<mat-icon [svgIcon]="item"></mat-icon>
</mat-grid-tile>

3,修改样式
让icon变圆。
<form>
<mat-card class="example-card">
<mat-card-header>
<mat-card-title>注册:</mat-card-title>
</mat-card-header>
<mat-card-content>
<mat-form-field class="full-width">
<input type="text" matInput placeholder="您的姓名" style="text-align: right">
</mat-form-field>
<mat-form-field class="full-width">
<input type="text" matInput placeholder="您的email" style="text-align: right">
</mat-form-field>
<mat-form-field class="full-width">
<input type="password" matInput placeholder="您的密码" style="text-align: right">
</mat-form-field>
<mat-form-field class="full-width">
<input type="password" matInput placeholder="重复输入您的密码" style="text-align: right">
</mat-form-field>
<mat-grid-list cols="6">
<mat-grid-tile *ngFor="let item of items">
<mat-icon class="avatar" [svgIcon]="item"></mat-icon>
</mat-grid-tile>
</mat-grid-list>
<button mat-raised-button type="button" color="primary">注册</button> </mat-card-content>
<mat-card-actions class="text-right">
<p>还没有账户?<a href="">注册</a></p>
<p>忘记密码?<a href="">找回</a></p>
</mat-card-actions>
</mat-card>
</form>
mat-icon.avatar {
overflow: hidden;
width: 64px;
height: 64px;
border-radius: 50%;
margin: 12px;
}
mat-card {
width: 600px;
}
.full-width {
width: 100%;
}

三、相关报错TroubleShoting
ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'login'
之前路由配置
AppRoutingModule里这样配置
LoginRoutingModule里这样配置
const routes: Routes = [
{path: '', redirectTo: '/login', pathMatch: 'full'},
{path:'login',loadChildren:'./login/login.module#LoginModule'}
];
Angular Taskmgr 登录的更多相关文章
- 使用angluar-cli的ng g component home指令出现的错误
Error: ELOOP: too many symbolic links encountered, stat '/Users/zzy/angular/taskmgr/node_modules/@an ...
- angular利用ui-router登录检查
angular利用ui-router登录检查 SAP都会有这个问题,session过期或者页面被刷新的情况下应该进入登录页. 监听ui-router的satte事件可以实现当state切换的时候检查登 ...
- Angular4--提速--提升Angular项目的首页打开速度(包含微信登录优化)
Angular项目的首页打开速度很慢,有时候会有几秒的加载时间.如果在手机端访问的话,怕是要等待十多秒,这对用户体验很差.下面参考http://www.cnblogs.com/feiyu159/p/8 ...
- angular中的 登录检查 和 过期Session清理
angular利用ui-router进行登录检查 SAP都会有这个问题,session过期或者页面被刷新的情况下应该进入登录页. 监听ui-router的satte事件可以实现当state切换的时候检 ...
- wcf 登录认证 angular 认证重定向
自定义认证管理器,分为两级:1.登陆认证.2.权限认证.权限主要是用户.角色.角色用户关系.功能(系统资源).角色功能关系,5部分决定用户的权限(视图). 两层认证都通过后,更新session的最新交 ...
- Angular之简单的登录注册
使用Angular实现了一个简单的登录注册的功能........ 涉及到的Angular知识点很少 主要是这个功能的实现...(*^__^*) 嘻嘻…… 里面涉及到的知识点记录: 1.本地存储的操作 ...
- Spring Security登录超时,angular ajax请求出错自动跳转至登录页(jQuery也适用)
公司开发采用Spring Security+AngualerJS框架,在session过期之后,ajax请求会直接出错.本文介绍如何实现出错情况下自动跳转至登录页. 整体思路是,session过期后, ...
- angular.js 验证码注册登录
css部分 header{ height: 50px; line-height: 50px; display: flex; } .callback{ text-align: left; display ...
- abp + angular 前端使用 hash ,登录界面不跳转问题
abp 项目默认的路由没有使用hash,这会导致手动刷新浏览器时,页面404错误: 解决方法网上很多,就是在路由里添加一个{useHash: true},就行了. #用Hash带来的新问题# abp框 ...
随机推荐
- bzoj3168 钙铁锌硒维生素 (矩阵求逆+二分图最小字典序匹配)
设第一套为A,第二套为B 先对于每个B[i]判断他能否替代A[j],即B[i]与其他的A线性无关 设$B[i]=\sum\limits_{k}{c[k]*A[k]}$,那么只要看c[j]是否等于零即可 ...
- PWN! 第一次测试答案及讲解
题目链接:https://vjudge.net/contest/279567#overview 题目密码:190118 1.A+B:(考察点:EOF输入.加法运算) Topic: Calculate ...
- java实现 链表反转
输入一个链表,反转链表后,输出新链表的表头. 递归法 public class RevnNode { public static class Node { public int value; publ ...
- centos7 部署安装gitlab服务器
概念: git 是一种版本控制系统,是一个命令,是一种工具 gitlib 是用于实现git功能的开发库 github 是一个基于git实现的在线代码托管仓库,包含一个网站界面,向互联网开放 gitla ...
- VS配置Halcon(一次配置,永久使用)
[说明]只需配置一次,以后新项目无需再次配置. 本教程是64位版本,32位可参考本教程.VS与Halcon无论哪个版本,都可参考本教程. [步骤]以VS2015+Halcon18.11为例 1.新建一 ...
- flask 出现 TemplateNotFound的问题
from flask import Flask, render_template, request app = Flask(__name__,template_folder='./templates' ...
- 非阻塞connect:Web客户程序
一.web.h #include <stdio.h> #include <netdb.h> #include <errno.h> #include <fc ...
- MVC系统过滤器 OutputCacheAttribute
命名空间: System.Web.Mvc程序集: System.Web.Mvc(在 System.Web.Mvc.dll 中) 一.MVC缓存简介 缓存是将信息(数据或页面)放在内存中以避免频繁的 ...
- Node的express配置使用ejs模板
注册ejs模板为html页.以.ejs为后缀的模板页,现在的后缀名可以是.html app.engine('.html', require('ejs').__express); 设置视图模板的默认后缀 ...
- Java基础 -- Java 抽象类 抽象方法
总结: 1. 抽象类不能被实例化(初学者很容易犯的错),如果被实例化,就会报错,编译无法通过.只有抽象类的非抽象子类可以创建对象. 2. 抽象类中不一定包含抽象方法,但是有抽象方法的类必定是抽象类. ...