扫码关注官方订阅号
http://www.alloyteam.com/2015...
这篇简单讲了angularjs依赖注入的原理,想知道ng2是如何实现依赖注入的?
angular2的注入其实可以在构造器constructor里完成。例如你发的例子里有注入http,那在angular2里可以写成
constructor
http
constructor(private http: Http){}
前提是要引用Http模块
Http
import { Http } from '@angular/http';
需要调用http方法的地方只需要
this.http.get()....
就行了。其他方法也类似,具体可以去官网看看
推荐你一个ng2入门视频,看第二节
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
扫描下载App
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
angular2的注入其实可以在构造器
constructor
里完成。例如你发的例子里有注入
http
,那在angular2里可以写成前提是要引用
Http
模块需要调用
http
方法的地方只需要就行了。
其他方法也类似,具体可以去官网看看
推荐你一个ng2入门视频,看第二节