Error: Can't resolve 'rxjs/add/operator/filter' in 'J:\auction\src\app\content'

来源:3-9 改造股票管理应用

慕粉4270219

2018-11-17

![图片描述]引入 了包为什么还报错,引的不对吗?(http://img.mukewang.com/szimg/5befc1b30001581e03890334.jpg)

写回答

3回答

DawnHope

2018-11-23

这个问题有人回答了

https://coding.imooc.com/learn/questiondetail/68790.html

这样写

//引入
import { filter} from 'rxjs/operators';


//构造器
constructor(public  router: Router) {
 this.router.events.pipe(
   filter((event: Event) => event instanceof NavigationEnd)
 ).subscribe((event: NavigationEnd) => {
   if (event.url === '/dashboard') {
     this.pageTitle = '这里是首页';
     this.pageDesc = '';
   } else if (event.url.startsWith('/stock')) {
     this.pageTitle = '股票信息管理';
     this.pageDesc = '进行股票信息基本增删改查';
   }
 });
}

0
1
慕粉4270219
非常感谢!
2018-11-24
共1条回复

wtxy

2018-11-20

import { Component, OnInit } from '@angular/core';
import {filter, map} from 'rxjs/operators';
import {Router, NavigationEnd} from "@angular/router";

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

  pageTitle = '';
  pageDesc = '';

  constructor(public router: Router) {
    //新版本rxjs filter要放在pipe中用
    const filterRouter = router.events.pipe(
      filter(event => event instanceof NavigationEnd)
    );
    filterRouter.subscribe((event: NavigationEnd) => {
      if (event.url == '/dashboard') {
        this.pageTitle = '这里是首页';
        this.pageDesc = '首页描述';
      } else if (event.url.startsWith('/stock')) {
        this.pageTitle = '股票信息管理';
        this.pageDesc = '股票信息基本增删改查';
      }
    })
  }

  ngOnInit() {
  }

}


0
0

wtxy

2018-11-18

你搜索一下问题: 

引入 rxjs 失败

有同学问过,这是新版本rxjs用法不同的问题,下面是炫酷同学的回到,亲试有效,

以后这课程遇到问题,可以尝试搜索以前同学的问题,一般你遇到的很可能以前就有人遇到了。。。

good luck

//img.mukewang.com/szimg/5bf184a600015fec09880783.jpg

0
1
慕粉4270219
试了试几种方法都不行,你说的不是很明白
2018-11-20
共1条回复

Angular4.0从入门到实战 打造股票管理网站

Angular新特性,教你熟练使用 Angular 和 Typescript 开发组件式单页应用

2683 学习 · 1361 问题

查看课程