How to handle datetime between php (Laravel api) and javascript (AngularJS)

前端 未结 2 1589
一生所求
一生所求 2021-02-01 06:52

I\'m utterly stuck trying to make php api exchange dates with angular frontend.

From PHP to JS I seem to have it sorted. Since Laravel handles dates through Carbon I jus

2条回答
  •  无人共我
    2021-02-01 07:07

    1) make a Carbon date in Laravel controller

    $date_from = Carbon::now();
    return view('reports', compact('date_from'));
    

    2) You need to init Date in Angular conctoller

    rrApp.controller('reportsCtrl', ['$scope', '$filter', function($scope, $filter)
    {
            $scope.start_date = new Date("{{$date_from}}");
            $scope.start_date = new Date($filter("date")($scope.start_date, 'yyyy-MM-dd'));// only date, no time
    
    }]); 
    

    3) use it

    
    

    4) Do NOT try to init the variable in ng-init, it would not work:

提交回复
热议问题