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?
phpcn_u15822017-07-04 13:46:32
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
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