这是我的activation.component.ts
import { Component, OnInit } from '@angular/core';
import { MyserviceService } from '../myservice.service';
import { ActivatedRoute, Router } from '@angular/router';
import {FlashMessagesService} from 'angular2-flash-messages';
@Component({
selector: 'app-activationpage',
templateUrl: './activationpage.component.html',
styleUrls: ['./activationpage.component.css']
})
export class ActivationpageComponent implements OnInit {
message;
messageClass;
constructor(private flashMessage:FlashMessagesService,private _service:MyserviceService,private _router:Router,private route: ActivatedRoute) {
}
ngOnInit() {
this.activate(this.route.snapshot.params['token']);
}
activate(token)
{
this._service.activate('http://localhost:3000/users/activate'+token).subscribe(data=>{
if(data.success)
{
console.log('success');
this.messageClass = 'alert alert-success'; // Set a success class
this.message = data.message; // Set a success message
}else{
console.log('fail');
this.messageClass = 'alert alert-danger'; // Set an error class
this.message = data.message; // Set an error message
}
});
}
}
这是我的服务。
activate(token)
{
let headers = new Headers();
headers.append('Content-Type','application/json');
return this.http.put('http://localhost:3000/users/activate'+token,{headers: headers})
.map(res=>res.json());
}
我想获取后端消息,我的后端nodejs正常工作,在前端我收到诸如“无令牌提供”之类的消息。我是新来的用户,请帮助我,如何在服务中加载令牌。
答案 0 :(得分:0)
从componen.ts中,您无需发送基本URL,只需单独传递令牌
activate(token)
{
this._service.activate(token).subscribe(data=>{
});