Javascript NullInjectorError:没有AuthenticationService的提供程序?
这是身份验证页面:-Javascript NullInjectorError:没有AuthenticationService的提供程序?,javascript,angular,ionic-framework,web,ionic4,Javascript,Angular,Ionic Framework,Web,Ionic4,这是身份验证页面:- 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
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);
});
});
}
}
您需要在
@Injectable
decorator中指定要提供此服务的位置
@Injectable({
providedIn: 'root'
})
export class AuthenticationService {
...
}
或者将其添加到app.module.ts
providers中:
providers: [
AuthenticationService,
any other services,
...
]