之前指令裝載比方說,我加載一個變量爲$範圍與$ HTTP:AngularJS數據
$http.get('/teachers/4').success(function(data){
$scope.teacher = data;
});
我的模板使用這樣的數據:
Teacher: {{teacher.name}}
<students-view students="teacher.students"></students-view>
這個指令可以加載之前老師完成加載,但我的指令有代碼取決於teacher.students陣列被加載:
app.directive('studentsView', function(){
return {
scope: { students: '=' },
controller: function($scope){
_.each($scope.students, function(s){
// this is not called if teacher loads after this directive
});
}
};
});
我該如何得到我想要的行爲?我不想停止使用$ http,如果可能的話,我不希望爲範圍分配一個承諾。
循環中發生了什麼?可以將該循環放入控制器中的成功回調中,如果這有助於或將整個請求移動到服務中 – charlietfl 2014-12-19 00:00:34