$ http.get未在指令

时间:2017-01-10 19:14:34

标签: jquery angularjs

我在我的指令($http.get

中进行了myApp.directive('wizard', function ($http) { });调用
$http.get('/api/TimeSlotsAPI').then(function(result) {

  if (result.data.length == 0) {
    toggleSteps($scope.currentStepIndex + 4);
  } else {
    $scope.dateTimeSlots = result.data;
    toggleSteps($scope.currentStepIndex + 1);
  }

});

$ http.get调用被调用,当我console.log结果时,我得到了预期的结果,如果我控制日志$ scope.dateTimeSlots它有预期的结果。

但是我的下拉列表不会包含结果。

<select class="form-control" name="timeSlot" ng-model="user.dateTimeSlot" ng-options="x.timeSlot as x.dateSlot for x in dateTimeSlots" ng-blur="blur22=true" required style="float: none; margin: 0 auto;"></select>

我在这里做错了什么?

以下是console.log返回的屏幕截图:

enter image description here

这是json响应

[{"id":1,"dateSlot":"Monday February 6th, 2017 - 6:00pm","timeSlot":"Monday February 6th, 2017-6:00pm","order":1},{"id":2,"dateSlot":"Monday February 6th, 2017 - 6:30pm","timeSlot":"Monday February 6th, 2017-6:30pm","order":2},{"id":3,"dateSlot":"Monday February 6th, 2017 - 7:00pm","timeSlot":"Monday February 6th, 2017-7:00pm","order":3},{"id":4,"dateSlot":"Monday February 6th, 2017 - 7:30pm","timeSlot":"Monday February 6th, 2017-7:30pm","order":4},{"id":5,"dateSlot":"Monday February 6th, 2017 - 8:00pm","timeSlot":"Monday February 6th, 2017-8:00pm","order":5},{"id":6,"dateSlot":"Monday February 6th, 2017 - 8:30pm","timeSlot":"Monday February 6th, 2017-8:30pm","order":6}]

更新,我不认为这与ng-options有任何关系,如果我把$ http.get放在指令之外并把它放在angular.module.controller中它完美地运行,我的下拉列表就会被填充,它只是不会在指令中填充。

0 个答案:

没有答案