Angularjs指令数据远程请求的处理
2014年9月6日 · 57 字 · 1 分钟
假设有一个指令用来根据IP地址进行地位,获取实际地址。 首先,我们的IP地址是由后台PHP程序返回的,这里需要一个Http请求,使用了Http请求就会有类似回调的问题,之前想了各种办法,死活拿不到数据,后来去ng官网看了下,需要使用ngModel,这个是双向绑定。 指令代码 app.directive('location', ['ApiService', function (ApiService) { return { restrict: 'A', require:'ngModel', link: function (scope, ele, attrs,ngModel) { ele.