请问这样为什么获取不到httpdata,是因为异步的关系吗,该怎么解决?
//父级
app.directive('d1',function(){
return{
controller:function($scope,$sce,$http){
var _this = this;
_this.httpdata = '';
$http.get('data/data.json')
.success(function(data,state){
_this.httpdata = data.elements;
})
.error(function(err,state){
alert(state)
});
}
}
});
//子级
app.directive('d2',function(){
return{
require:'^d1',
link:function(scope,elements,attrs,cntIns){
console.log(cntIns.httpdata)
}
}
慕标5832272
相关分类