84669 person learning
152542 person learning
20005 person learning
5487 person learning
7821 person learning
359900 person learning
3350 person learning
180660 person learning
48569 person learning
18603 person learning
40936 person learning
1549 person learning
1183 person learning
32909 person learning
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 injectionhttp, which can be written as
constructor
http
constructor(private http: Http){}
The prerequisite is to reference theHttpmodule
Http
import { Http } from '@angular/http';
Where you need to call thehttpmethod, 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