Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
948 views
in Technique[技术] by (71.8m points)

typescript - Angular2: Inject a non @Injectable class

angular: 2.0.0-beta.9

Is it possible to inject a non @Injectable class into a component ? For example, this class could come from a Third party library.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Yes, it's possible. In fact the @Injectable decorator isn't to specify that a class is injectable into other ones but that you want to inject something in it at the level of its constructor.

If you don't want to inject something in your class, it's not mandatory to add the @Injectable decorator. This class can be injected into other ones.

I think that this Github issue could help you:

What is important here is to understand the difference between decorators and annotations. Here is a great article on this subject:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...