javascript - How is dependency injection implemented in angular2
过去多啦不再A梦
过去多啦不再A梦 2017-07-04 13:44:32
0
2
983

http://www.alloyteam.com/2015...

This article briefly talks about the principle of dependency injection in angularjs. I want to know how ng2 implements dependency injection?

过去多啦不再A梦
过去多啦不再A梦

reply all(2)
phpcn_u1582

The injection of

angular2 can actually be completed in the constructorconstructor.
For example, the example you posted contains injection http, which can be written as

in angular2
constructor(private http: Http){}

The prerequisite is to reference the Http module

import { Http } from '@angular/http';

Where you need to call the http method, you only need

this.http.get()....

That’s it.
Other methods are also similar, you can check the official website for details

巴扎黑

I recommend you an introductory video to ng2, watch the second section

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template