Я использую Angular 6.1.1, и у меня есть модель класса, которой требуется внедренная служебная переменная.
Есть ли какой-нибудь способ создать экземпляр моего класса, не предоставив DI?
Может быть, я делаю это неправильно, как правильно использовать angular в этом случае.
Заранее спасибо
Цель состоит в том, чтобы добиться этого с помощью хорошо внедренного сервиса в классе
@Injectable({
providedIn: 'root'
})
export class AuthenticationService {
public User : User = new User();
constructor() { }
}
export class Item {
public UserCreator: User;
// Other properties
constructor(private authenticationService : AuthenticationService) {
this.UserCreator = this.authenticationService.User;
}
}
export class ExampleComponent {
constructor() {
const newItem : Item = new Item();
//Doesn't compiled because need authenticationService argument
//Is there any way to ask Angular to instanciate this class with auto resolving the injection of the authenticationService ?
}
}