控制器中的angularjs$scope.item值是否预先确定?

iswrvxsc  于 2021-09-29  发布在  Java
关注(0)|答案(0)|浏览(204)

我还是angularjs的新手,最近遇到了一些需要更新的代码。我想我有点明白了 $scope ,但后来我偶然发现了这个控制器,其中有一个 $scope.value 这在以前似乎有价值 $scope.item 甚至在同一控制器内创建(并指定任何值)。
另外,我不明白这个函数是如何工作的 $scope.showAppointmentDetailInIndex 可以从此控制器访问,尽管它是在另一个控制器中定义的。
我错过了什么?
我的理解是 AngularJS 必须首先执行查询(通过 servicefactory 对象)从数据库中获取数据,然后将其保存到 $scope.objects 在进入整个系统之前 Controller 以及相应的dom-like HTML .
这是我说的 AngularJS Controller (其中两个示例标有注解):

angular.module('MyApp').controller('AppointmentsEditController', function(Appointment, Order, Person, $scope,$state,$stateParams){
  $scope.data = {
    'loadingComplete': false,
    'editErrorText':'',
    'isSubmitting': false
  };

  $scope.setEventEditing(true);

  Appointment.get({id: $stateParams.id})
    .$promise.then(
      //success
      function(appointment) {
        $scope.appointment = appointment;

        if($scope.tempAppointment != undefined){
          $scope.appointment = $scope.tempAppointment;
          $scope.setTempAppointment(undefined);
        }

        var start_mom = moment(appointment.start)
        var end_mom = moment(appointment.end)

        if($scope.appointment.allDay){
          $scope.appointment.start = start_mom.format('DD-MMM-YYYY');
          $scope.appointment.end = end_mom.subtract(1, 'days').format('DD-MMM-YYYY');
        }else{
          $scope.appointment.start = start_mom.format('DD-MMM-YYYY');
          $scope.appointment.end = end_mom.format('DD-MMM-YYYY');
          $scope.appointment.startTime = start_mom.format('HH:mm');
          $scope.appointment.endTime = end_mom.format('HH:mm');
        }

        $scope.showAppointmentDetailInIndex($scope.appointment);    //  <-- how can this function be accessed from here 
        $scope.data.loadingComplete = true;                         //      while being defined whithin another controller?

      }
    );

  $scope.saveAppointment = function(appointment){$scope.data.editErrorText = '';

    angular.forEach($scope.editForm, function(val, key){
      if(!key.match(/\$/)) {
        val.$pristine = false;
      }
    });

    if($scope.editForm.$invalid) {
      $scope.data.editErrorText = 'Please fill all marked fields.';
      return;
    }

    if (($scope.generalists.activeIDs.length + $scope.instruments.activeIDs.length) == 0){ // <-- where does $scope.generalists come from?
      $scope.data.editErrorText = 'Please select at least one sprecialist or instrument.';
      return;
    }

    if (!$scope.selectedAppointment.order){
      $scope.data.editErrorText = 'Please select an order from the list on the right.';
      return;
    }

    var editAppointment = angular.copy(appointment);
    editAppointment.allDay = $scope.selectedAppointment.allDay;
    editAppointment.participantIDs = $scope.generalists.activeIDs;
    editAppointment.instrumentIDs = $scope.instruments.activeIDs;
    ...
    ...

  };
  ...
});

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题