ページをロードするときに小さな問題があります。場合によっては、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
};
});
コントローラー:
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>