相关疑难解决方法(0)

订阅不存在"订阅"类型

我是angualr 2的新手.我正在做一个小练习.我有一个用户在登录时对用户进行身份验证的服务.这是它的登录功能.

login(email:string, password:string){

        var loginrul="https://filing.herokuapp.com/api/v1/auth/login/";
        return this.http.post(loginrul,JSON.stringify({  password: password,email: email }),
            {headers:new Headers({'Content-Type':'application/json'})}
            ).map(res=>res.json()).
            subscribe(
                data => localStorage.setItem('id_token',data.auth_token),
                error=>console.log(error)
            );
    }
Run Code Online (Sandbox Code Playgroud)

当我在组件中调用此函数时,angualr会给出"属性订阅不存在于'订阅'上的错误".

doLogin(event) {
        console.log(event);
        console.log(this.loginForm.value);


        let formData = this.loginForm.value;
        let email = this.loginForm.controls.email.value;
        let password= this.loginForm.controls.password.value;
        this.auth.login(email,password).subscribe(res =>{
            console.log(res);
            if(res.status===200){
                this.router.navigate(['dashboard']);
            }
        }
        )
    }
Run Code Online (Sandbox Code Playgroud)

我认为为什么angular会出现这个错误,因为我在登录功能中使用订阅以及在调用登录功能时.请建议一些解决方案或替代方法来实现我在登录功能中尝试实现的结果.

typescript angular

6
推荐指数
1
解决办法
1万
查看次数

标签 统计

angular ×1

typescript ×1