◆◆◆Angular2学习笔记-问题解决方法

❖❖淘宝镜像❖❖

淘宝 NPM 镜像 https://npm.taobao.org/

1、设置淘宝镜像

安装:命令提示符执行npm install cnpm -g --registry=https://registry.npm.taobao.org;  注意:安装完后最好查看其版本号cnpm -v或关闭命令提示符重新打开,安装完直接使用有可能会出现错误;

注:cnpm跟npm用法完全一致,只是在执行命令时将npm改为cnpm(以下操作将以cnpm代替npm)。


2、取消淘宝镜像/切换镜像

❖How to configure yarn to use private registry ?

https://www.npmjs.com/package/nrm

Install

$ npm install -g nrm

Example

$ nrm ls
 
* npm -----  https://registry.npmjs.org/
  cnpm ----  http://r.cnpmjs.org/
  taobao --  https://registry.npm.taobao.org/
  nj ------  https://registry.nodejitsu.com/
  rednpm -- http://registry.mirror.cqupt.edu.cn
  skimdb -- https://skimdb.npmjs.com/registry
  
$ nrm use cnpm  //switch registry to cnpm
    Registry has been set to: http://r.cnpmjs.org/
    

Usage

Usage: nrm [options] [command]
 
  Commands:
 
    ls                           List all the registries
    use <registry>               Change registry to registry
    add <registry> <url> [home]  Add one custom registry
    del <registry>               Delete one custom registry
    home <registry> [browser]    Open the homepage of registry with optional browser
    test [registry]              Show the response time for one or all registries
    help                         Print this help
 
  Options:
 
    -h, --help     output usage information
    -V, --version  output the version number


3、Angular2的包管理

设置以后Angular2的所有包都从cnpm下载。

命令 :ng set --global packageManager=cnpm


4、Angular2项目中如何导入第三方库



5、如何解决ng init报错

ng init --name=XXX会报错。

The specified command init is invalid. For available options, see `ng help`

出错环境

node:v6.11.2

npm:3.10.10

angular/cli:1.3.2

webstorm:2016.3.2

解决办法 :更新WebStorm版本

webstorm:2017.2.2


6、Angular2中如何传递多个参数
方法1:
→路由定义: 
const routes: Routes = [
  { path: '', redirectTo: '/goodsList', pathMatch: 'full' },
  { path: 'goodDetail/:id/:kbn', component: GoodDetailComponent }
];
→参数设置:
gotoDetail(good: Good): void  {
  this.router.navigate(['/goodDetail', {id: good.id, kbn: 'H'}]);
}

→参数获取:

ngOnInit(): void {
  console.log('GoodDetailComponent>ngOninit');
  this.router.paramMap
    .switchMap((parms: ParamMap) => this.goodsService.getGoodById(+parms.get('id'), parms.get('kbn')))
    .subscribe(good => this.good = good);
}

方法2:

→路由定义: 
const routes: Routes = [
  { path: '', redirectTo: '/goodsList', pathMatch: 'full' },
  { path: 'goodDetail', component: GoodDetailComponent }
];
→参数设置:
gotoDetail(good: Good): void  {
this.router.navigate(['/goodDetail'], {queryParams: {id: good.id, kbn: 'H'}});
}

→参数获取:

ngOnInit(): void {
  this.router.queryParamMap
    .switchMap((parms: ParamMap) => this.goodsService.getGoodById(+parms.get('id'), parms.get('kbn')))
    .subscribe(good => this.good = good);
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值