2014-06-23 6 views
0

AngularJS로 작성된 보고서 생성기가 있습니다. jQuery datepicker를 사용하지 않으면 잘 작동합니다. jQuery datepicker를 사용할 때 서버에서 되돌아 오는 데이터는 정확하지만 프런트 엔드는 변경되지 않습니다. 제가 순수한 각도로 가면, 아래에서 보여 주듯이이 작품은 아름답게 작동합니까? 대답은 간단합니다. 문제를 피하기 위해 각도 코드가있는 각도 날짜표를 사용 하시겠습니까? 내 AngularJS와 컨트롤러에서서버 요청 후 각도 데이터가 업데이트되지 않습니다.

내가 가진 :

as.controller('ReportController', function ($scope, $rootScope, $http, $location) { 

var currentDate = new Date(); 
// works 
$scope.loadToday = function() { 
    // not sure why this is necessary here 
    currentDate = new Date(); 
    $scope.load(); 
}; 

// does not work 
$scope.setDateAndLoad = function (newDate) { 
    $scope.currentDate = newDate; 
    $scope.load(); 
}; 

$scope.decrementWeekAndLoad = function() { 
    currentDate.setDate(currentDate.getDate() - 7); 
    $scope.load(); 
};  


// works depending on method 
$scope.load = function() { 
    $scope.showTable = false; 
    $scope.currentDate.setHours(0, 0, 0, 0); 
    var formattedDate = $scope.currentDate.toISOString(); 
    $http.get('/app/client/report/${user.id}?startDate=' + formattedDate) 
     .success(function (data, status, headers, config) { 
     $scope.report = angular.copy(data); 
     // $scope.report is not getting rebound 
     $scope.showTable = true; 
    }); 
}; 

$scope.loadToday(); 

그리고 다음과 같은 HTML 코드에 바인딩 : JQuery와의 날짜 선택기에서

<section id="show-client" class="first" ng-app="myApp"> 
<div id="reportController" class="form-group" ng-controller="ReportController"> 
    <div ng-hide="showTable"> 
     Loading . . . 
    </div> 
    <div ng-show="showTable"> 
     Behavior {{report}} 
    </div> 

    <input id="datepicker" name="datepicker" class="datepicker"> 

내가 가진 :

$(document).ready(function() { 
    $('#datepicker').datepicker({ 
     dateFormat: 'dd-M-yyyy' 
    }).on('changeDate', function (ev) { 
     var newDate = new Date(ev.date); 
     angular.element('#reportController').scope().setDateAndLoad(newDate); 
     $(this).datepicker('hide'); 
    }); 
}); 
+0

jqLite를 사용하지 않고 jQuery 이벤트를 처리 할 때 $ scope. $ apply (fn)로 코드를 래핑하여 다이제스트주기를 트리거하십시오. – pixelbits

+0

나는 당신이 같은 결과로 제안한 것을했습니다. . jQuery 대신 암시 적으로 jqLite를 사용하는 것과 관련된 내 방식의 오류가 발생했습니다. jQuery는 jQuery보다 먼저 각도를 포함시킬 때 발생합니다. –

답변

0

오래된 순서를 : - 각도 - jQuery - 각도 (예 포함 회)

새로운 질서 : - jQuery를 - 예상대로 각도

작품.

관련 문제