[ask] Menampilkan Data Memakai Method Post AngularJS

Halo, karena ini copas dari stack ane pengin nanya nih: Hi, thank you for reading this, I have a problem with angular again... The problem is so complicated and I have search in google and also in this forum but until now no answer are solving my problem, so here is the problem. I am running a localhost, our goal is to make (if you can see the image above) when the user click "tambahkan", then the blank field above yellow button "lanjutkan" appear the list of the things that the user "tambahkan" via the green button (I hope everyone understand the flow) The problem is, somehow I am confused about how to defined the data from the list of items, so I can throw it into the field above "lanjutkan", anyone can help me? Here is the codes: Index.html (for the fields only, the code are too long that I think there's no need to show all of them here)
<div class="container-customscroll">
                                    <div class="content mCustomScrollbar">
                                        <div class="itemcheck" ng-repeat="item in dataItem.stores | regex:'name':alfabet | orderBy: 'name' | filter: searchItem">
                                            <div class="left" ng-if="item.preparation == ''" ng-model="name"><i class="fa fa-circle silver"></i>{{item.name}}</div>
                      <div class="left" ng-if="item.preparation == '1'" ng-model="name"><i class="fa fa-circle green"></i>{{item.name}}</div>
                      <div class="left" ng-if="item.preparation == '2'" ng-model="name"><i class="fa fa-circle yellow"></i>{{item.name}}</div>
                      <div class="left" ng-if="item.preparation == '3'" ng-model="name"><i class="fa fa-circle pink"></i>{{item.name}}</div>
                                            <div class="right" ng-click="addToCart()"><a>+ Tambahkan</a> </div>
                                        </div>
                                    </div><!-- /mCustomScrollbar -->
                                </div><!-- /container-customscroll -->

<div class="col-md-4">
                <div class="container-sidebaryellow">
                    <div class="title">Pemeriksaan Ditambahkan</div>
                    <div class="container-customscroll">
                        <div class="content mCustomScrollbar">
                            <div class="item-tambahan ">
                                <div class="item checkuptambahan" ng-repeat="cart in tambahCart">
                                    <i class="fa fa-circle pink">{{cart.name}}</i>
                                    <a class="checkuptambahan">x</a>
                                </div>
                            </div>
                        </div><!-- /content -->
                    </div><!-- /container-customscroll -->
                    <a href="#" class="btn btnyellow">Lanjutkan</a>
                </div>
            </div>
here is the angular code:
var app = angular.module('pesanlab', []);
app.controller('pesanlabCtrl', function($scope,$http){
    //variabel awal
    $scope.showMe = false;
    $scope.myFunc = function() {
        $scope.showMe = !$scope.showMe;
    }


    $scope.aksi = "tambah";

    //code untuk mengeluarkan data dari data/item.json
    $scope.dapatkanItem = function(){
    $http.get('/someurl').success(function(data){
      $scope.dataItem = data;
    });
    }

    $scope.dapatkanItem();

    $scope.dapatkanPanel = function(){
    $http.get('/someurl').success(function(data){
      $scope.dataPanel = data;
    });
    }

    $scope.dapatkanPanel();

    $scope.dapatkanPaket = function(){
        $http.get('/someurl').success(function(data){
           $scope.dataPaket = data;
        });
    }

    $scope.dapatkanPaket();

    $scope.addToCart = function(){
        $http({
          method: 'POST',
          url: '/someurl',
          headers: {
            "Access-Control-Allow-Origin" : "*",
            "Access-Control-Allow-Methods" : "GET,POST,PUT,DELETE,OPTIONS",
            "Access-Control-Allow-Headers": "Content-Type, Authorization, X-Requested-With"
          },
          data: {
          //  master_code: $scope.name,
            name: $scope.item
          }
        }).success(function(data, status, headers, config){
          $scope.tambahkan = data;
        });
        console.log($scope.item)
    }

    $scope.tambahkanCart = function(){
        $http.get('/someurl').success(function(data, status, headers, config){
           $scope.tambahCart = data;
        });
    }

    $scope.tambahkanCart();
    });

    app.filter('regex', function() {
          return function(input, field, regex) {
              var patt = new RegExp(regex);
              var out = [];

              if(input === undefined){
                  return out;
              }
              for (var i = 0; i < input.length; i++){
                  if(patt.test(input[i][field]))
                      out.push(input[i]);
              }
            return out;
          };
    });
and when the console.log are functioning, it returns as "undefined" and also we are using api in website based (I don't know what it's called), and it returns like this, we are using laravel 5.2 for the back-end Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://dev.pesanlab.com/api/v1/order/cart/add. (Reason: missing token 'access-control-allow-headers' in CORS header 'Access-Control-Allow-Headers' from CORS preflight channel). Can anyone help me? Thank you so much
avatar yupangestu

Ditanyakan oleh @yupangestu

64 Kontribusi 22 Poin

Login untuk menanggapi


Jawaban

maslaahnya yang CORS seprtinya, intinya ngga diizinkan cross script, harusnya sih dari backend nya atua yang bikin laravelnya suruh bikin allow ini, ada plugin kalo ngga salah atau bisa explisit ditulis langusng allow cors di header pas ngasih data http://laravel.io/forum/07-05-2014-no-access-control-allow-origin-header-is-present-on-the-requested-resource
avatar immeng

Dijawab oleh @immeng

10 Kontribusi 18 Poin

Login untuk menanggapi


kalo kamu pakai chrome buat dev, coba install ini https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi
avatar ma4m

Dijawab oleh @ma4m

97 Kontribusi 39 Poin

Login untuk menanggapi


Login untuk gabung berdiskusi