对应代码:
- material组件
1. material.module.ts
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import {
MatCardModule,
MatFormFieldModule,
MatInputModule,
MatTableModule,
MatSortModule,
MatPaginatorModule,
MatSliderModule,
MatOptionModule,
MatAutocompleteModule,
MatSlideToggleModule,
MatCheckboxModule,
MatSelectModule,
MatRadioModule,
MatButtonModule,
MatDatepickerModule,
MatNativeDateModule,
MatIconModule,
MatMenuModule,
MatTabsModule,
MatExpansionModule,
} from '@angular/material';
import { ReactiveFormsModule,FormsModule } from '@angular/forms';
import { MaterialComponent } from './material.component';
const Material = [
MatCardModule,
MatFormFieldModule,
MatInputModule,
ReactiveFormsModule,
MatTableModule,
MatSortModule,
MatPaginatorModule,
MatSliderModule,
MatOptionModule,
MatAutocompleteModule,
MatSlideToggleModule,
MatCheckboxModule,
FormsModule,
MatSelectModule,
MatRadioModule,
MatButtonModule,
MatDatepickerModule,
MatNativeDateModule,
MatIconModule,
MatMenuModule,
MatTabsModule,
MatExpansionModule,
];
@NgModule({
declarations: [MaterialComponent],
imports: [
CommonModule,
Material
],
//暴露组件和模块,可以在app中使用(弹窗要用到)
exports: [Material,MaterialComponent]
})
export class MaterialModule { }
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 公共组件
2. app.component.html
<router-outlet></router-outlet>
- 1
- 配置路由组件
3. app-routing.module.ts
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
//引入组件配置路由
import {HomeComponent} from './home/home.component';
import {ManageOrderComponent} from './order/manage-order/manage-order.component';
//配置路由器
const routes: Routes = [
{path: 'home', component: HomeComponent},
{path: 'manage-order', component: ManageOrderComponent},
{path: '',redirectTo: '/home',pathMatch: 'full'}
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 主页组件
4. home.component.html
<!--1.顶部导航条部分 -->
<!-- 顶部导航条外部容器 -->
<div class="topbar-wrapper">
<!-- 创建内部容器 -->
<div class="topbar w clearfix">
<!-- 左侧导航条 -->
<ul class="title-city a1">
<!-- 城市选择部分 -->
<li class="city">
<a href="javascript:;"><i class="material-icons">place</i>{{selectedcity}}<i class="material-icons">arrow_drop_down</i></a>
</li>
<li>
<div class="city-content">
<mat-form-field class="select-city-content1">
<mat-select placeholder="省份/地区" [(ngModel)]="selectedprovince" name="省份/地区" >
<mat-option *ngFor="let province of provincelist" [value]="province">
{{province.province}}
</mat-option>
</mat-select>
</mat-form-field>
<mat-form-field class="select-city-content2">
<mat-select placeholder="城市" [(ngModel)]="selectedcity" name="城市" >
<mat-option *ngFor="let city of selectedprovince.citylist" [value]="city">
{{city}}
</mat-option>
</mat-select>
</mat-form-field>
</div>
</li>
</ul>
<ul class="title-language a1">
<li class="language"><a href="javascript:;"><i class="material-icons">public</i>简体中文-CNY<i class="material-icons">arrow_drop_down</i></a></li>
</ul>
<!-- 由于需要设置浮动,所以将购物车和用户位置颠倒 -->
<!-- 购物车 -->
<ul class="shop-cart">
<li>
<a [routerLink]="[ '/manage-order' ]" class="shop-cart-a" href="javascript:;"> <i class="material-icons md-dark">shopping_cart</i>购物车(0)
<!-- 添加一个弹出层 -->
<div class="shop-cart-popup">
购物车中还没有商品,赶紧选购吧!
</div>
</a>
</li>
</ul>
<!-- 用户登录注册 -->
<ul class="user-info a1">
<li class="user-login"><a href="javascript:;" (click)="openDialog1()">欢迎,请登录</a></li>
<li class="line">|</li>
<li class="user-reg"><a href="javascript:;" (click)="openDialog2()">注册</a></li>
<li class="user-man"><a href="javascript:;">客服中心</a></li>
</ul>
</div>
</div>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
5. home.component.css
/* 公共样式 */
/* 下面的样式可以解决高度塌陷 */
.clearfix::before,.clearfix::after{
content: '';
display: table;
clear: both;
}
/* 设置一个类,用来表示中间容器的宽度 */
.w{
/* 固定容器的宽度 */
width: 1100px;
/* 设置容器居中 */
margin: 0 auto;
}
/* 解决图标和文字的不对齐问题 */
.material-icons{
vertical-align:bottom;
margin-bottom: 4px;
}
/* home样式 */
/* 1. 顶部导航条外部容器 */
.topbar-wrapper{
/* 设置宽度全屏 */
width: 100%;
/* 设置高度和行高(为了让文字居中) */
height: 30px;
line-height: 30px;
/* 设置背景颜色 */
background-color:rgb(250, 250,250);
font-size: 13px;
}
/* 设置超链接的样式 */
.a1 a{
color:rgb(112, 112,112) ;
/* 转换为块元素 */
display: block;
}
/* 超链接的伪类--鼠标移入发生变化 */
.a1 a:hover{
color:rgb(225, 37,27);
}
/* 设置导航条 */
.title-language,
.title-city
{
/* 向左浮动 */
float: left;
}
.shop-cart, .user-info{
/* 向右浮动 */
float: right;
}
/* |的样式 */
.line{
color:rgb(121, 121,121);
margin: 0 3px;
}
/* 调整列表li样式 */
.topbar .title-language li,
.topbar .user-info li{
/* 向左浮动 */
float: left;
}
/* 为列表中每个内容设置样式 */
.topbar .title-city .city{
/* 城市和语言之间的间距 */
margin-right: 15px;
}
.topbar .user-info .user-man{
margin-left: 20px;
margin-right: 30px;
}
/* 城市选择框外面的容器样式 */
.title-city .city-content{
/* width: 370px; */
width: 220px;
background-color: #fff;
position: absolute;
/* 设置层级 */
z-index: 200;
margin-left: 0;
/* 隐藏下拉 */
height: 0;
overflow: hidden;
/* transition 用于为样式设置过渡效果 */
transition: height 0.5s;
box-shadow: 0.5px 0px 5px 2px rgba(237,237,237,0.54);
}
.title-city:hover .city-content{
/* height: 310px; */
height: 120px;
}
/* 城市选择框的样式 */
.example-small-box, .example-large-box {
display: flex;
align-items: center;
justify-content: center;
margin: 12px;
padding: 12px;
border-radius: 8px;
}
.example-small-box {
height: 210px;
width: 320px;
}
.example-large-box {
height: 210px;
width: 320px;
}
/* 城市选择框内容样式 */
.select-city-content1,
.select-city-content2{
margin-left: 18px;
}
.select-city-content1{
margin-top: 10px;
}
/* 设置购物车样式 */
.shop-cart a{
width: 140px;
background-color:rgb(0, 99, 186) ;
text-align: center;
color: #fff;
display: block;
}
/* 鼠标移入发生变化 */
.shop-cart:hover a{
background-color: rgb(35, 26, 102);
color:#fff ;
}
.shop-cart i{
margin-right: 10px;
color: #fff;
}
.shop-cart{
margin-left: 45px;
}
/* 设置购物车下拉框的样式*/
.shop-cart-a .shop-cart-popup{
width: 270px;
/* height: 65px; */
background-color: #fff;
color:rgb(121, 121,121);
font-size: 14px;
margin-left: -130.7px;
/* 绝对定位 */
position: absolute;
/* 设置层级 */
z-index: 100;
/* 隐藏下拉 */
/* display: none; */
height: 0;
overflow: hidden;
/* transition 用于为样式设置过渡效果 */
transition: height 0.5s;
/* 设置文字居中 */
line-height: 65px;
border-style: solid;
border-width: 1px;
border-color: rgb(250, 250,250);
}
.shop-cart-a:hover .shop-cart-popup{
/* 出现下拉 */
/* display: block; */
height: 65px;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
- 131
- 132
- 133
- 134
- 135
- 136
- 137
- 138
- 139
- 140
- 141
- 142
- 143
- 144
- 145
- 146
- 147
- 148
- 149
- 150
- 151
- 152
- 153
- 154
- 155
- 156
- 157
- 158
- 159
- 160
- 161
- 162
- 163
- 164
- 165
- 166
- 167
- 168
- 169
- 170
- 171
- 172
- 173
- 174
- 175
- 176
- 177
- 178
- 179
6. home.component.ts
import { Component, OnInit,ChangeDetectorRef } from '@angular/core';
import {MediaMatcher} from '@angular/cdk/layout';
import {MatDialog} from '@angular/material/dialog';
//引入弹出框的组件
import {LoginComponent} from '../user/login/login.component';
import {RegistrationComponent} from '../user/registration/registration.component';
//弹窗
export interface DialogData {
animal: string;
name: string;
}
@Component({
selector: 'app-home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.css']
})
export class HomeComponent implements OnInit {
//弹出框定义变量
animal: string;
name: string;
mobileQuery: MediaQueryList;
private _mobileQueryListener: () => void;
//城市选择
public selectedprovince:any={};
public selectedcity:any[];
constructor(changeDetectorRef: ChangeDetectorRef, media: MediaMatcher,
public dialog: MatDialog //弹出框
) {
this.mobileQuery = media.matchMedia('(max-width: 700px)');
this._mobileQueryListener = () => changeDetectorRef.detectChanges();
this.mobileQuery.addListener(this._mobileQueryListener);
}
ngOnInit(): void {
//初始化
this.selectedcity=["城市"];
}
public provincelist:any[]=[
{
province:"北京市",
citylist:["北京市"]
},
{
province:"天津市",
citylist:["天津市"]
},
{
province:"上海市",
citylist:["上海市"]
},
{
province:"山东省",
citylist:["济南市","青岛市", "聊城市", "德州市","东营市", "淄博市","潍坊市","烟台市", "威海市","日照市", "临沂市", "枣庄市","济宁市","泰安市","莱芜市","滨州市","菏泽市"]
},
{
province:"新疆",
citylist:[ "乌鲁木齐市", "克拉玛依市", "自治区直辖县级行政单位","喀什地区","阿克苏地区","和田地区","吐鲁番地区","哈密地区","克孜勒苏柯州","博尔塔拉州","昌吉州","巴音郭楞州","伊犁州","塔城地区","阿勒泰地区"]
},
{
province:"重庆市",
citylist:["重庆市"]
},
{
province:"河北省",
citylist:["石家庄市","张家口市", "承德市","秦皇岛市", "唐山市","廊坊市","保定市","衡水市", "沧州市","邯郸市"]
},
{
province:"山西省",
citylist:["太原市","朔州市","大同市", "阳泉市","长治市", "晋城市", "忻州市","晋中市","临汾市", "吕梁市", "运城市"]
},
{
province:"内蒙古",
citylist:["呼和浩特市","包头市","乌海市","赤峰市", "通辽市","呼伦贝尔市", "鄂尔多斯市","乌兰察布市", "巴彦淖尔市","兴安盟","锡林郭勒盟","阿拉善盟"]
},
{
province:"辽宁省",
citylist:["沈阳市", "朝阳市", "阜新市","铁岭市","抚顺市","本溪市", "辽阳市","鞍山市", "丹东市","大连市","营口市","盘锦市","锦州市","葫芦岛市"]
},
{
province:"吉林省",
citylist:[ "长春市", "白城市","松原市","吉林市","四平市", "辽源市", "通化市","白山市", "延边州"]
},
{
province:"黑龙江省",
citylist:["哈尔滨市", "齐齐哈尔市","七台河市","黑河市", "大庆市", "鹤岗市","伊春市", "佳木斯市", "双鸭山市", "鸡西市","牡丹江市","绥化市","大兴安岭地区"]
},
{
province:"江苏省",
citylist:[ "南京市", "徐州市","连云港市", "宿迁市","淮安市","盐城市","扬州市", "泰州市","南通市","镇江市", "常州市", "无锡市", "苏州市"]
},
{
province:"浙江省",
citylist:["杭州市","湖州市","嘉兴市","舟山市","宁波市","绍兴市","衢州市","金华市","台州市","温州市", "丽水市"]
},
{
province: "安徽省",
citylist:["合肥市", "宿州市","淮北市","亳州市","阜阳市","蚌埠市", "淮南市", "滁州市","马鞍山市","芜湖市", "铜陵市", "安庆市","黄山市","六安市","巢湖市","池州市", "宣城市"]
},
{
province: "福建省",
citylist:[ "福州市", "南平市","莆田市", "三明市","泉州市", "厦门市","漳州市","龙岩市","宁德市"]
},
{
province:"江西省",
citylist:["南昌市","九江市","景德镇市", "鹰潭市", "新余市","萍乡市","赣州市", "上饶市", "抚州市","宜春市", "吉安市"]
},
{
province:"河南省",
citylist:["郑州市","开封市", "三门峡市","洛阳市", "焦作市", "新乡市","鹤壁市","安阳市", "濮阳市","商丘市", "许昌市","漯河市","平顶山市","南阳市", "信阳市","周口市","驻马店市","济源市"]
},
{
province: "湖北省",
citylist:["武汉市", "十堰市","襄樊市","荆门市","孝感市","黄冈市","鄂州市","黄石市","咸宁市","荆州市","宜昌市","随州市","省直辖县级行政单位","恩施州"]
},
{
province:"湖南省",
citylist:["长沙市", "张家界市","常德市", "益阳市","岳阳市","株洲市","湘潭市","衡阳市","郴州市","永州市","邵阳市","怀化市","娄底市","湘西州"]
},
{
province:"广东省",
citylist:["广州市", "深圳市","清远市","韶关市","河源市","梅州市","潮州市","汕头市","揭阳市","汕尾市","惠州市","东莞市","珠海市","中山市","江门市","佛山市","肇庆市","云浮市","阳江市","茂名市","湛江市"]
},
{
province:"广西",
citylist:[ "南宁市", "桂林市", "柳州市","梧州市","贵港市", "玉林市", "钦州市", "北海市","防城港市","崇左市", "百色市","河池市","来宾市","贺州市"]
},
{
province:"海南省",
citylist:[ "海口市","三亚市", "省直辖行政单位"]
},
{
province: "四川省",
citylist:["成都市", "广元市","绵阳市","德阳市","南充市","广安市", "遂宁市","内江市","乐山市","自贡市","泸州市","宜宾市","攀枝花市","巴中市","达州市","资阳市","眉山市", "雅安市","阿坝州","甘孜州","凉山州"]
},
{
province:"贵州省",
citylist:["贵阳市","六盘水市","遵义市","安顺市","毕节地区","铜仁地区","黔东南州","黔南州","黔西南州"]
},
{
province:"云南省",
citylist:["昆明市","曲靖市","玉溪市","保山市","昭通市","丽江市","思茅市","临沧市","德宏州","怒江州","迪庆州","大理州","楚雄州","红河州","文山州","西双版纳州"]
},
{
province:"西藏",
citylist:["拉萨市","那曲地区","昌都地区","林芝地区","山南地区", "日喀则地区","阿里地区"]
},
{
province:"陕西省",
citylist:["西安市","延安市","铜川市","渭南市","咸阳市","宝鸡市","汉中市","榆林市","安康市","商洛市"]
},
{
province:"甘肃省",
citylist:[ "兰州市","嘉峪关市","白银市","天水市","武威市","酒泉市","张掖市","庆阳市","平凉市","定西市","陇南市","临夏州","甘南州"]
},
{
province:"青海省",
citylist:[ "西宁市", "海东地区","海北州","海南州","黄南州", "果洛州", "玉树州","海西州"]
},
{
province:"宁夏",
citylist:[ "银川市","石嘴山市", "吴忠市", "固原市", "中卫市"]
},
{
province:"北京",
citylist:["北京"]
},
{
province:"北京",
citylist:["北京"]
},
{
province:"香港",
citylist:["香港"]
},
{
province:"澳门",
citylist:["澳门"]
},
{
province:"台湾",
citylist:["台北","高雄","台中","花莲", "基隆","嘉义","金门","连江","苗栗","南投","澎湖","屏东","台东","台南","桃园","新竹","宜兰","云林","彰化"]
},
]
//自定义方法
//登录弹出框的方法
openDialog1(): void {
//弹出
const dialogRef = this.dialog.open(LoginComponent, {
width: '320px',
data: {name: this.name, animal: this.animal}
});
dialogRef.afterClosed().subscribe(result => {
this.animal = result;
});
}
// 注册弹出框的方法
openDialog2(): void {
//弹出
const dialogRef = this.dialog.open(RegistrationComponent, {
width: '320px',
data: {name: this.name, animal: this.animal}
});
dialogRef.afterClosed().subscribe(result => {
this.animal = result;
});
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
- 131
- 132
- 133
- 134
- 135
- 136
- 137
- 138
- 139
- 140
- 141
- 142
- 143
- 144
- 145
- 146
- 147
- 148
- 149
- 150
- 151
- 152
- 153
- 154
- 155
- 156
- 157
- 158
- 159
- 160
- 161
- 162
- 163
- 164
- 165
- 166
- 167
- 168
- 169
- 170
- 171
- 172
- 173
- 174
- 175
- 176
- 177
- 178
- 179
- 180
- 181
- 182
- 183
- 184
- 185
- 186
- 187
- 188
- 189
- 190
- 191
- 192
- 193
- 194
- 195
- 196
- 197
- 198
- 199
- 200
- 201
- 202
- 203
- 204
- 205
- 206
- 207
- 208
- 209
- 210
- 211
- 212
- 213
- 214
- 215
- 216
- 217
- 218
- 219
- 220
- 221
- 222
- 223
- 224
- 225
- 226
- 227
- 228
- 229
- 230
- 231
- 232
- 233
- 234
- 235
- 236
- 237
- 238
- 239
- 240
- 241
- 242
- 243
- 244
- 245
- 246
- 247
- 248
- 249
- 250
- 251
- 252
登录注册弹窗原参考引用代码网址:http://iyenn.com/rec/1648188.html
- 登录组件
7. login.component.html
账号登录
账号:
"outline">
输入用户名/手机号/邮箱
(ngModel)]="data.animal">
密码:
"outline">
输入密码
(ngModel)]="data.animal">
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
8. login.component.ts
import { Component, OnInit,Inject } from '@angular/core';
import { DialogData } from '../../home/home.component';
import { MatDialogRef, MAT_DIALOG_DATA} from '@angular/material/dialog';
@Component({
selector: 'app-login',
templateUrl: './login.component.html',
styleUrls: ['./login.component.css']
})
export class LoginComponent implements OnInit {
constructor(
public dialogRef: MatDialogRef<LoginComponent>,
@Inject(MAT_DIALOG_DATA) public data: DialogData){}
onNoClick(): void {
this.dialogRef.close();
}
ngOnInit() {
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 注册组件
9. registration.component.html
注册账号
账号:
"outline">
输入用户名/手机号/邮箱
(ngModel)]="data.animal">
密码:
"outline">
输入密码
(ngModel)]="data.animal">
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
10. registration.component.ts
import { Component, OnInit,Inject } from '@angular/core';
import { DialogData } from '../../home/home.component';
import { MatDialogRef, MAT_DIALOG_DATA} from '@angular/material/dialog';
@Component({
selector: 'app-registration',
templateUrl: './registration.component.html',
styleUrls: ['./registration.component.css']
})
export class RegistrationComponent implements OnInit {
constructor(
public dialogRef: MatDialogRef<RegistrationComponent>,
@Inject(MAT_DIALOG_DATA) public data: DialogData){}
onNoClick(): void {
this.dialogRef.close();
}
ngOnInit() {
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 购物车组件
11. manage-order.component.html
欢迎来到购物车页面!
此页面是order中的manage-order组件
"[ '/home' ]" >返回首页
- 1
- 2
- 3
评论记录:
回复评论: