未解决的函数或方法映射

时间:2017-07-12 10:59:34

标签: angular webstorm

我写了下一个服务:

import { Injectable } from '@angular/core';
import { Http, Response, Headers } from '@angular/http';
import 'rxjs/Rx';

import { AppConfig } from '../appConfig';
import { User } from '../models/user.model';
import { JwtService } from '../services/jwt.service';

@Injectable()
export class UserService {

  constructor(
      private http: Http,
      private appConfig: AppConfig,
      private jwtService: JwtService) {}

  create(user: User) {
    return this.http.post(this.appConfig.urlServer + '/auth/signup', user)
        .map((res: Response) => res.json())
  }
}

我在组件中使用服务方法:

import { Component } from '@angular/core';
import { Router } from '@angular/router';

import { UserService } from '../shared/services/user.service';
import { User } from '../shared/models/user.model';

@Component({
  selector: 'app-registration',
  templateUrl: './registration.component.html',
  styleUrls: ['./registration.component.scss']
})
export class RegistrationComponent {

  errorMessage: string;

  constructor(
      private userService: UserService,
      private router: Router) {}

  register(user: User) {
    this.errorMessage = '';
    this.userService.create(user).subscribe(
        () => {
          this.router.navigateByUrl('/');
        },
        err => {
          this.errorMessage = 'User already was created';
        }
    );
  }

}

一切正常,但当我在方法map上指示鼠标光标时,我会看到下一个错误:

Unresolved function or method map()

我正在使用Angular 4.我的IDE是WebStorm,它的版本是2016.2.3。我的应用程序是由Angular CLI创建的。我的package.json是:

{
  "name": "client",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^4.0.0",
    "@angular/common": "^4.0.0",
    "@angular/compiler": "^4.0.0",
    "@angular/core": "^4.0.0",
    "@angular/forms": "^4.0.0",
    "@angular/http": "^4.0.0",
    "@angular/platform-browser": "^4.0.0",
    "@angular/platform-browser-dynamic": "^4.0.0",
    "@angular/router": "^4.0.0",
    "bootstrap-sass": "^3.3.7",
    "core-js": "^2.4.1",
    "rxjs": "^5.1.0",
    "zone.js": "^0.8.4"
  },
  "devDependencies": {
    "@angular/cli": "1.1.0",
    "@angular/compiler-cli": "^4.0.0",
    "@angular/language-service": "^4.0.0",
    "@types/jasmine": "2.5.45",
    "@types/node": "~6.0.60",
    "codelyzer": "~3.0.1",
    "jasmine-core": "~2.6.2",
    "jasmine-spec-reporter": "~4.1.0",
    "karma": "~1.7.0",
    "karma-chrome-launcher": "~2.1.1",
    "karma-cli": "~1.0.1",
    "karma-coverage-istanbul-reporter": "^1.2.1",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "node-sass": "^4.5.3",
    "protractor": "~5.1.2",
    "sass-loader": "^6.0.6",
    "ts-node": "~3.0.4",
    "tslint": "~5.3.2",
    "typescript": "~2.3.3"
  }
}

我通过stackoverflow搜索了我的问题的答案,但不幸的是,它对我没有帮助。也许,我严厉地搜索了答案:(。

0 个答案:

没有答案