2014-10-08 62 views
0

在我的angularjs應用程序中,我對標準的實現方式有點困惑。請看看我的代碼結構,並提出一些建議以使其更有效。AngularJs +查看/更新數據的最佳實踐 - 更新後再次重新加載模型中的數據

var app = angular.module("UserApp", []); 

    app.controller('UsersListCtrl', function ($scope, $http) { 
    $http.get('/ShowAllUsersList.json').success(function(data) { 
     $scope.users = data; 
    }); 
    }); 

    $http.get('/LoggedInUserInfo.json'). 
    success(function(data, status, headers, config) { 
     $scope.logged_in_user = data; 
    }). 
    error(function(data, status, headers, config) { 
     // log error 
    }); 
    }  

    app.controller("LoggedInUserInfoCtrl", ['$scope', '$http', function($scope, $http) { 
    $scope.updatePersonalInfo = function() { 
     $scope.user_personal_info = { 
     username: $scope.logged_in_user.username, 
     primary_email: $scope.logged_in_user.primary_email, 

     first_name: $('#first_name').val(), 
     last_name: $('#last_name').val(), 
     secondary_email: $('#secondary_email').val(), 
     }; 

     $http.put('/UpdatePersonalInfo', $scope.user_personal_info). 
     success(function(data, status, headers, config) { 
      alert('Data updated successfully.'); 
     }). 
     error(function(data, status, headers, config) { 
      alert('error'); 
     }); 
    }; 

    }]); 

現在我沒有辦法重新加載範圍內的數據完全沒有重新加載頁面。我試圖把onload函數,但它沒有工作。請提出建議。

在此先感謝

回答