I've a question about injecting a service into a domain model, in a way
that it'd allow me to instantiate (`new`) that domain model.
Imagine I have a domain model called `Book`. I need to inject a service
called `Books` into this domain model, so that I can call the
`Books.create()` method from the `Book.create()` method.
If I inject the service dependency in the domain model's constructor, I am
not able to `new` that domain model, unless I pass an instance of the
service into the domain model.
Domain model:
~~~
class Book {
id: number;
name: string;
constructor (
private Books: Books
){}
create (){
this.Books.create(//pass data here);
}
}
~~~
Component:
~~~
class BooksCreateComponent {
create(){
let book = new Book(); //This fails unless I pass in an instance of
Books service.
boook.id = 149;
book.name = 'TMA - 1';
book.create();
}
}
~~~
Any idea how I should proceed?
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.