加载页面时遇到一个小问题。有时,我的ng-options
有空值。我不明白为什么。我可以毫无问题地加载页面10次,但我可以使用空白值加载页面。
但是,返回的JSON不是空白。总是一样的结果:
服务:
myApp.factory('GenericService', function ($http, $q) {
var data;
function getDataIfNeeded(the_action) {
the_action = the_action || 'default';
if (data !== undefined) {
return $q.when(data);
}
return $http({
url: "php/functions.php",
method: "GET",
params: {
action: the_action
}
}).then(function(response) {
data = response.data;
return data;
});
}
return {
getData: getDataIfNeeded
};
});
CONTROLLER:
GenericService.getData("get_leaders").then(function (data) {
$scope.leaders = data;
});
...
GenericService.getData("get_experts_ux").then(function (data) {
$scope.experts_ux = data;
});
JSON:
[
{"lead_technique_id":1,"lead_technique_name":"Delphine ____"},
{"lead_technique_id":2,"lead_technique_name":"Thierry ____"}
]
HTML:
<select ng-model="newProject.lead_technique_id" ng-options="leader.lead_technique_id as leader.lead_technique_name for leader in leaders" required></select>