angular cli 切换 css_angular视频学习笔记

angular2/4命令:

1,安装 Angular CLI npm install -g @angular/cli

6,#全局安装 Angular CLI (可以例用 ng -v 查看安装的版本信息)

2,ng serve --open

(ng serve命令会启动开发服务器,监听文件变化,并在修改这些文件时重新构建此应用。使用--open(或-o)参数可以自动打开浏览器并访问http://localhost:4200/。)

216851c4c4ed93a05f4ad2478b7c56a2.png

754fecc11cfb14e49f09de368a77a68d.png

3,D:(到该目录)

4,dir(该目录所有文件)

5,.ts转换成js--- $ tsc xxx.ts (把 function(){} 替换为 () =>:)

....ng new (创建得项目名字);生成得文件以下:..........

e2e:(端对端,自动测试);

assets:(存放静态资源,如:图片);

environments:();

import {Component, OnInit} from '@angular/core';

@Component({
  selector: 'app-product',
  templateUrl: './product.component.html',
  styleUrls: ['./product.component.css']
})
export class ProductComponent implements OnInit {
  private products:Array<Product>;

  constructor() {
  }

  ngOnInit() {
    let a = this.products = [//视频中this.products = [{}]报错
      new Product(1, '商品标题1', 1.99, 3.5, '第一个商品', ['电子', '网购']),
      new Product(2, '商品标题2', 1.99, 3.5, '第一个商品', ['电子', '网购']),
      new Product(3, '商品标题3', 1.99, 3.5, '第一个商品', ['电子', '网购']),
      new Product(4, '商品标题4', 1.99, 3.5, '第一个商品', ['电子', '网购']),
      new Product(5, '商品标题5', 1.99, 3.5, '第一个商品', ['电子', '网购']),
      new Product(6, '商品标题6', 1.99, 3.5, '第一个商品', ['电子', '网购'])
    ];
    a.push(new Product(6, '商品标题6', 1.99, 3.5, '第一个商品', ['电子', '网购']))
  }

}
export class Product {
  constructor(public id:number,
              public title:string,
              public price:number,
              public rating:number,
              public desc:string,
              public categories:Array<string>) {
  }
}

.......................

有路由得项目:ng new router --routing

新建文件报错:npm install @angular-devkit/core

.........................

ng g component xxx(就会生成模块组件:xxx.component.css/html/.spec.ts),app.module.ts会随之更新

5,cnpm install @types/jqurey --save-dev(引入的jq使用的时候会报错,所以要安装types)

6,<li *ngFor="let message of mailService.messages; index as i;">(我们使用 let item of items; 语法迭代数组中的每一项,另外我们使用 index as i 用来访问数组中每一项的索引值,必须是双引号)

angular路由

087ecb43fdb8369ece94acd951be9b7e.png
import { NgModule } from '@angular/core';  
import { Routes, RouterModule } from '@angular/router';  
import { HomeComponent } from './home/home.component';  
import { ProductComponent } from './product/product.component';  
import { Code404Component } from './code404/code404.component';  
 
//Routes:这里是根路由 
const routes: Routes = [  
 //path:指路由的路径。component:指路由的目标组件 
  { path:'' , component:HomeComponent},  
  { path:'product' , component:ProductComponent},   
 
 //这里配置的是一个页面不存在的路由 
  { path:'**' , component:Code404Component},  
];  
 
@NgModule({  
  imports: [RouterModule.forRoot(routes)],  
  exports: [RouterModule]  
})  
export class AppRoutingModule {  
  constructor(){  
 
  }  
 }  

product.component.html

3.
<h4><a [routerLink]="['/product',product.title]" >{{product.title}}</a></h4>

product-detail.component.ts

import { Component, OnInit } from '@angular/core';
import {ActivatedRoute} from "@angular/router";

@Component({
  selector: 'app-product-detail',
  templateUrl: './product-detail.component.html',
  styleUrls: ['./product-detail.component.css']
})
export class ProductDetailComponent implements OnInit {

  productTitle:string;

  constructor(private routeInfo:ActivatedRoute) { }

  ngOnInit() {
    this.productTitle = this.routeInfo.snapshot.params["productTitle"]
  }


8771eda4e1a48497034ef935387cf1dc.png

①,当path:' ',redirectTo意思是重定向路由,也就是一进来就显示重定向的路由地址'/home'.

②,path:'**',意识是找不到所指的路由时候显示的内容

插座的指定于路由的区分:辅助路由

0a9da60530429150f76a37ac4583bd3a.png

2dcdb5ac607dc9ad442bbc05d48d95be.png

fe70a74beeed269e8f22782e941c3cf1.png

a4e894130838e8c060a121acaf1e35e6.png

@input 的用法:

d9ec30fbfae8bfdf30001c18fea8c7df.png

3fb5602ec3419873fb714edc0f45fd6e.png

@Input是用来定义模块的输入的,用来让父模块往子模块传递内容:

父级的Html,<app-star>是组件
<app-stars [rating]="product.rating"></app-stars>
组件的html:
{{rating}}星
组件的js:
@Input()
  private rating:number=0;

0b13f9b3fc86b9bfe699813b7e324b1a.png

e3165c8518835dc11f696aa0dc268a11.png
<!--路由切换位置
将来通过路由显示的组件都会在该标签下方
-->
<router-outlet></router-outlet>

025cd48803479f560f222335368a54ee.png

CSS类绑定

df708ad9188908aa553b7244d5ce6051.png

1,会替换原来的class.

2,是否添加一个special的类.

3,添加多个样式.

样式绑定

99b83d2899184fde5c383eb27c7f8c4b.png

html绑定

错误的绑定方式:

5570b3d0ea2a3cd8965056d05b88dc05.png

正确的:

9a7691ec1dee95d3546119520d157505.png

双向绑定1:[(ngModel)]

af01085b12cceda8d66e35225c68747f.png

双向绑定2:

dab9928d231a5af3d2b48e57fd63bc42.png

双向绑定报错原因:

dbc206b35356491b6ea427472ceff87e.png

b8f26cd946069d7a5926120dff86b478.png

解决方案:

44b731d5b0976ecc84986fa6591e431f.png

fec1b8957f1218eefee822845d3308a5.png

管道

960dc23fcfb2a5dc924d97e03b225ecd.png

701f407edf85825f2cd7442253a81dda.png

自定义管道:

10e572529bd6b110a707d1327acdc9ea.png

会自动添加:

b918a1855a22cec943b74a0265290693.png

7b90c468d5899e4d8c7ee6c9abbd9460.png

列子:

462551a5f6207fd090e502590845259c.png
Html:
<p>自己写的管道{{size | multiple:2}}</p>
ts:
size:number = 7;

[formControl]

formControl 的监听与广播

两种监听方式

1. control.valueChanges.subscribe(v)  
2. control.registerOnChange((value, emitViewToModelChange)

a3ecdd014c73b12514dfcb23a8a2ed18.png

87a5556347c5b43db0c3d1bd6d2ce90b.png

01efc547d6be107397dc69e8c7be54f9.png

0dd3d03a1eb03ff5b7c2b9fce3d2e479.png

....生命周期钩子

4d6e72a2cf11609fcb117d189879ff9e.png

1,ngOnChanges(子组件)监听input输入

4c2155097c9cdee0140bf981f1dbd341.png

95595f140787b5036b1301e5faa0726b.png

b69d2fc8e9362cc5a0e5bd41dc15a39a.png

cmd命令:

1,tracert 是一个简单的网络诊断工具,可以列出分组经过的路由节点,以及它在IP 网络中每一跳的延迟。(这里的延迟是指:分组从信息源发送到目的地所需的时间,延迟也分为许多的种类——传播延迟、传输延迟、处理延迟、排队延迟等,是大多数网站性能的瓶颈之一)

2,cls:清除所有

58b4c2313c7b4a80624ac55ac468f659.png
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值