请问这样为什么获取不到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)
}
}
});
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
欢迎选择我的课程,让我们一起见证您的进步~~