2014-05-05 32 views
1

我跑在NG-點擊此功能,但得到了一個錯誤類型錯誤:未定義是不是在這條線的功能:$scope.$apply(function() {

app.controller('MainControl', function($scope, $http){ 

$scope.add = function(){ 

    $http({ 
     url: "php/insert.php", 
     method: "POST", 
     data: { 
      'myId': myId 
     }, 
     headers: { 
      'Content-Type': 'application/x-www-form-urlencoded' 
     } 
    }).success(function (data, status, headers, config) { 

     $scope.$apply(function() { 
      $scope.currentId = data; 
     }); 

    }).error(function (data, status, headers, config) {}); 

    $scope.tabs.push({ 
     "currentId": $scope.currentId 
    }); 

} 

    }); 
+0

爲什麼要使用$範圍移動

$scope.tabs.push({ "currentId": $scope.currentId }); 

success回調的HTTP承諾。$申請的權利呢?這是沒有必要的。 –

回答

0

$scope.$apply()是這裏不需要。

app.controller('MainControl', function($scope, $http){ 

$scope.add = function(){ 

    $http({ 
     url: "php/insert.php", 
     method: "POST", 
     data: { 
      'myId': myId 
     }, 
     headers: { 
      'Content-Type': 'application/x-www-form-urlencoded' 
     } 
    }).success(function (data, status, headers, config) { 

     $scope.currentId = data; 
     $scope.tabs.push({ 
      "currentId": $scope.currentId 
     }); 

    }).error(function (data, status, headers, config) {}); 



} 

    }); 
相關問題