Saturday 15 September 2012

json - AngularJs + Best practice to view / update the data - after updation again reload the data in model -



json - AngularJs + Best practice to view / update the data - after updation again reload the data in model -

in angularjs app, little bit confused respect standard way of implementation. please have @ code construction , suggest create more effective.

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'); }); }; }]);

now not getting way reload info in scope out reloading of page. tried set onload function dnt work. please suggest something.

thanks in advance

you need create service persist info across controllers , scopes.

please read docs: https://docs.angularjs.org/guide/services

also video : https://egghead.io/lessons/angularjs-sharing-data-between-controllers

json angularjs

No comments:

Post a Comment