2017-01-23 2 views
0

내가하는 기능이 페이지를 새로 고침하는 방법 :()가 true를 완벽하게위치를 변경하고 각도 JS에서

$scope.insert = function(){ 
    var data = { 
     'username' : $scope.username, 
     'password' : $scope.password, 
     'nama_lengkap' : $scope.nama_lengkap 
    } 

    $http({ 
     method: 'POST', 
     url: './sys/mac.php', 
     data : data 
    }).then(function(response){ 
     return response.data; 
    }); 
} 

및 함수 작업을,하지만 난 DataList에 내 페이지 변화를 원하고 삽입 후 DataList에 새로 고칩니다. 내 함수 insert()는 "localhost/learn/#!/administrator"경로에서 실행되므로 insert() true 다음에 "localhost/learn/#! /"경로로 변경하고 싶습니다. location.href = '#! /'를 사용했지만 자동으로 데이터를 새로 고치기 위해 자동으로 작동하지 않고 위치 만 변경합니다.

+0

업데이트 할 구조를 게시해야하므로 변경해야 할 사항을 실제로 볼 수 있습니다. –

답변

0

서비스 호출에서 개체를 업데이트하려는 경우 다음을 수행 할 수 있습니다. 디버깅을 돕기 위해 onError 함수도 추가했습니다.

팁 : AngularJS 프레임 워크에서 제공하는 Service에 서비스 호출을 추가하는 방법 연구. 유지 보수가 가능하고 구조화 된 코드를 작성하는 데 도움이됩니다.

$scope.objectToUpdate; 
$scope.insert = function(){ 
    var data = { 
     'username' : $scope.username, 
     'password' : $scope.password, 
     'nama_lengkap' : $scope.nama_lengkap 
    } 

    $http({ 
     method: 'POST', 
     url: './sys/mac.php', 
     data : data 
    }).then(function(response){ 
     $scope.objectToUpdate = response.data.d; 
    }, function(e){ 
     alert(e); //catch error 
    }); 
    } 

옵션 서비스 아래

는 각도 서비스의 사용은 서버가

app.service('dataService', function ($http) { 
    delete $http.defaults.headers.common['X-Requested-With']; 
    this.getData = function (url, data) { 
     // $http() returns a $promise that we can add handlers with .then() in controller 
     return $http({ 
      method: 'POST', 
      url: './sys/' + url + '.php', 
      dataType: 'json', 
      data: data, 
      headers: { 'Content-Type': 'application/json; charset=utf-8' } 
     }); 
    }; 
}); 

그런 다음 컨트롤러에서이 서비스를 호출 통화를 할 수 있도록하는 방법의 예입니다, 또는 컨트롤러가 주사하다. DataService

var data = { 
      'username' : $scope.username, 
      'password' : $scope.password, 
      'nama_lengkap' : $scope.nama_lengkap 
     } 
dataService.getData('mac', data).then(function (e) { 
    $scope.objectToUpdate = e.data.d; 
}, function (error) { 
    alert(error); 
}); 
+0

지적 .. 고마워. –

+0

팁을 주셔서 감사합니다. –

+0

문제가 없으면 도움이 될만한 답을 표시하십시오. –

관련 문제