使用ng-options的angularJS错误

时间:2016-12-19 14:23:49

标签: javascript angularjs select ionic-framework ng-options

我正在开发一个从服务器接收JSON数组的应用程序,而不是在几天(3)和几天内分割它。在html文件中,有两个选项应该填充日期(第一个选择),并且在第一个选择中选择时间“属于”(在第二个选择中)。 我编写了一部分正确执行的代码,但这两个选项都是空的。

这是我的代码,

CONTROLLER.JS

ionicApp.controller('DefaultController', DefaultController)
  .factory('dataService', dataService);
DefaultController.$inject = ['dataService', '$http'];

function DefaultController(dataService, $http) {
  var vm = this;
  console.log("Dentro ctrl");
  getEvents();

  function getEvents() {
      console.log("Dentro getEvents");
    return dataService.getEvents()
      .then(function (data) {
          console.log(data);
        vm.data = data;
        console.log(vm.data);
        return vm.data;
      });
  }
    vm.submit = function (){
        console.log("funzione");
        console.log(vm.form);
        var data = vm.form; // IMPORTANT
        //console.clear();
        var link = 'http://localhost/ShuttleFIX/api/apiDoFix.php';
        var mail = window.localStorage.getItem("mail");
        var scelta = window.localStorage.getItem("scelta");
        console.log(data);
        $http.post(link, {giorno: data.giorno, ora: data.ora, mail: mail, scelta: scelta})
            .then(function (res){
                console.log("Dentro http.post");
                var response = res.data;
                if (response != 'F'){
                    console.log("Dentro if");
                    console.log(response);
                    window.location.href ="/main.html";
                } else {
                    console.log("Dentro else");
                }
            });
    };
}

dataService.$inject = ['$http'];

function dataService($http) {
    console.log("qua");
  var service = {
    getEvents: getEvents
  };

  return service;

  function getEvents() {
      console.log("qua2");
    var config = {
      transformResponse: function (data, headers) {
        var result = {
          events: [],
          schedules: []
        };
        var events = JSON.parse(data);
        var dates = [];
        console.log("qua3");
        for (var i = 0; i < events.length; i++) {
          if (dates.indexOf(events[i].day) === -1) {
            var date = events[i].day;
            dates.push(date);
            result.events.push({
              date: date
            });
          }

          result.schedules.push({
            date: events[i].day,
            time: events[i].time
            //console.log("qua4");
          });
        }
        console.log(result);
        return result;
      }
    };

    return $http.get('http://localhost/ShuttleFIX/api/apiTimes.php', config)
      .then(getEventsCompleted)
      .catch(getEventsFailed);
    function getEventsCompleted(response) {
        console.log(response.data);
      return response.data;
      console.log(response.data);
    }

    function getEventsFailed(error) {
      console.error(error);
    }
  }
}

HTML

<div class="list">
                                    <label class="item item-input item-select">
                                        <select ng-options="event as event.date for event in ctrl.data.events" ng-model="ctrl.form.giorno">
                                            <option disabled>Seleziona un giorno </option>
                                        </select>
                                    </label>
                                </div>

                                <div class="list">
                                    <label class="item item-input item-select">
                                        <select ng-options="schedule as schedule.time for schedule in ctrl.data.schedules| filter: { date: ctrl.form.giorno.date}" ng-model="ctrl.form.ora" ng-disabled="!ctrl.form.giorno">
                                            <option disabled>Seleziona un orario </option>
                                        </select>
                                    </label>
                                </div>

另一个“问题”是,如果我创建一个html文件,如果我修改js文件的第一行创建一个新模块,它就可以工作。

我该如何解决这个问题?

0 个答案:

没有答案