这是身份验证页面:-
import {Injectable} from '@angular/core';
import {HttpClient, HttpHeaders} from '@angular/common/http';
import {SECURITY} from '../constant/SecurityAPI';
import {CONFIG} from '../config';
@Injectable()
export class AuthenticationService {
constructor(private http: HttpClient) {
}
public isUserLoggedIn() {
return localStorage.getItem('token') === undefined;
}
public login(credentials) {
return new Promise((resolve, reject) => {
console.log('username ' , credentials.userName, ' pass ' , credentials.password );
const data = {userName: credentials.userName, password: credentials.password, orgId: CONFIG.ORG_ID};
this.http.post(SECURITY.GET_LOGIN_URL, JSON.stringify(data), {
headers: new HttpHeaders().set('Content-Type', 'application/json')
})
.subscribe(res => {
console.log('res ' , res);
resolve(res);
}, (err) => {
reject(err);
});
});
}
}
答案 0 :(得分:1)
您需要在@Injectable
装饰器中指定要提供此服务的位置
@Injectable({
providedIn: 'root'
})
export class AuthenticationService {
...
}
或将其添加到app.module.ts
提供者中:
providers: [
AuthenticationService,
any other services,
...
]