相关疑难解决方法(0)

类型'字符串|的参数 null'不能分配给'string'类型的参数.类型'null'不能分配给'string'类型

我有一个dotnetcore 20和angular4项目,我正在尝试创建一个userService并让用户访问我的home组件.后端工作正常,但服务没有.问题出在localStorage上.我的错误消息是:

类型'字符串|的参数 null'不能分配给'string'类型的参数.类型'null'不能分配给'string'类型.

和我的userService

import { User } from './../models/users';
import { AppConfig } from './../../app.config';
import { Injectable } from '@angular/core';
import { Http, Headers, RequestOptions, Response } from '@angular/http';



@Injectable()
export class UserService {
constructor(private http: Http, private config: AppConfig) { }

getAll() {
    return this.http.get(this.config.apiUrl + '/users', this.jwt()).map((response: Response) => response.json());
}

getById(_id: string) {
    return this.http.get(this.config.apiUrl + '/users/' + _id, this.jwt()).map((response: Response) => response.json());
}

create(user: User) {
    return this.http.post(this.config.apiUrl + '/users/register', user, …
Run Code Online (Sandbox Code Playgroud)

typescript .net-core asp.net-core angular

23
推荐指数
4
解决办法
2万
查看次数

标签 统计

.net-core ×1

angular ×1

asp.net-core ×1

typescript ×1