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框 ...
随机推荐
- luogu4055 游戏 (二分图博弈)
考虑对非障碍的点黑白染色然后做二分图最大匹配,那么有结论,先手必胜当且仅当不是完美匹配,而且可以放的点是那些可以不匹配的点 从非匹配点开始走,后手只能走到匹配点,于是先手就可以走匹配边.由于不能走走过 ...
- centos7环境搭建命令List
npm -ivh jdk-8u191-linux-x64.rpm adduser sai passwd sai whereis sudoers vim /etc/sudoers rpm -qa | g ...
- CTF--web
https://adworld.xctf.org.cn/task/task_list?type=web&number=3&grade=0 1.view source 查看源代码 1.鼠 ...
- 分布式协调服务Zookeeper集群搭建
分布式协调服务Zookeeper集群搭建 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.安装jdk环境 1>.操作环境 [root@node101.yinzhengjie ...
- 我的mybatis从oracle迁移转换mysql的差异【原】
仅此作为笔记 分页差异 oracle <select id="select" parameterClass="java.util.Map" resultC ...
- #2 numpy pandas初步学习记录
对numpy中的array进行了了解,array方法的取值arr_2d[0:2, 0:2] pandas 1,read_CSV方法 2,head方法 3,loc方法,取值前开后开, 4,replace ...
- Keras实现LSTM
一.先看一个Example 1.描述,输入为一个字母,输出为这个字母的下一个顺序字母 A->B B->C C->D 2.Code import numpy from keras.mo ...
- Selenium-ActionChainsApi--鼠标连贯操作
ActionChains UI自动化测试过程中,经常遇到那种,需要鼠标悬浮后,要操作的元素才会出现的这种场景,那么我们就要模拟鼠标悬浮到某一个位置,做一系列的连贯操作,Selenium给我们提供了Ac ...
- ASP.NET MVC - Entity Framework
ASP.NET MVC - Entity Framework 实体关系 关系是某个实体(表)的一条记录对应于另一个实体(表)的一条或多条记录. 一对多关系 单方面的包含关系称为一对多,而一对多和一对一 ...
- 搜索表字段包含某字符串的SQL和监控Oracle数据库的SQL。
1.第一个SQL 背景:需要找到SQL Server数据库中,包含某个字符串的表,输出表和包含该字符串的列. )='=' --这里填要搜索的字符串 DECLARE @sql NVARCHAR(MAX) ...