2014-11-11 6 views
0

아래와 같이 신청서에 기재했습니다.콘트롤러 내부의 설정 방법

module.provider('CalculateTime', function() { 


    this.$get = function() { 
     var seconds = this.seconds; 
     var minutes = this.minutes; 
     var hours = this.hours; 
     var day = this.day; 

     return { 

      toSeconds: function(){ 
       return Math.round(seconds); 
      },  

      toMinutes: function(){ 
       return Math.round(minutes); 
      }, 

      toHours: function(){ 
       return Math.round(hours); 
      },  

      toDays: function(){ 
       return Math.round(day); 
      }, 

      exactDate: function(){ 
        return Math.floor(hours%24)+":"+ Math.floor(minutes%60)+":"+ Math.floor(seconds%60);    
      }  
     } 
    }; 

    this.setTime = function(milis) { 

     this.milis = milis; 
     this.seconds = this.milis/1000; 
     this.minutes = this.seconds/60; 
     this.hours = this.minutes/60; 
     this.day = this.hours/24; 
    }; 
}); 

컨트롤러 내부에 구성을 설정하고 싶습니다 (일부 준비를 마친 후 설정). 그래서 나는 다음과 같이 시도했다.

module.controller('ResultController',function($scope,$data,CalculateTime){ 

    var date = $data.post.date; 

    given.setDate(date.selectedYear,date.selectedMonth,date.selectedDay); 

    var now = new DateTime(); 
    var diff = now.compare(given); 


    // config here   
    module.config(function(CalculateTimeProvider){ 
     CalculateTimeProvider.setTime(diff); 
    }); 


    setTimeout(function() { 
     $scope.$apply(function() { 
     $scope.result = CalculateTime.toDays() + " Days " + CalculateTime.exactDate(); 
     }); 
    }, 100); 

$ scope.result가 null이되어 아무것도 나오지 않습니다. 나는 내가 사용법에있어 틀림이없고 서비스 나 공급자 또는 공장을 사용하는 올바른 방법을 여전히 모르고 있음을 안다. 올바른 설정 및 검색 방법에 대해 알려주십시오.

답변

0

부트 스트랩 단계 후에 모듈을 구성 할 수 없습니다. 이전에 구성해야합니다. 컨트롤러 범위 밖에서이 작업을 수행해야합니다.

관련 문제