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?
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
http
constructor(private http: Http){}
The prerequisite is to reference the Http module
Http
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
The injection of
angular2 can actually be completed in the constructor
in angular2constructor
.For example, the example you posted contains injection
http
, which can be written asThe prerequisite is to reference the
Http
moduleWhere you need to call the
http
method, you only needThat’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