2013-07-17 19 views
0

在下面的代碼工作,print_label是鏈接到NG-點擊功能。所有從數據HTTP-GET顯示在文檔中,但是當我按一下按鈕,沒有任何反應。我如何從$ http.get調用分配數據?

invoice_app.controller('main_ctrl', function($scope, $http) { 
    $http.get(root_url + '/dummy_data.php') 
      .then(function(res){ 

       $scope.invoice = res.data; 

      $scope.print_label = function($scope) { 
       alert($scope.invoice.id); 
      }       
    }); 
}); 

回答

0

返回的數據可能是數組嗎?因爲我有它在plunker工作:http://plnkr.co/edit/YIfDNg?p=preview

+0

這很奇怪,因爲如果我使用$ http.get它的工作原理.success(數據)的功能。 – ddillert

+0

好吧,我知道了。在$範圍不能在我的print_label功能進行傳遞。如果我刪除它,它也適用於.then()。感謝張貼你的代碼,幫助我找到問題所在。 – ddillert