javascript - Syncing data between model instances in Angular -
i'm angular newb. i've followed tutorial http://www.bradoncode.com/tutorials/learn-mean-stack-tutorial/ , have modified things (i have items instead of categories). i've created mean app, 2 models, users , items. add property items model called "owner" stores username of user created model. isn't hard, problem arises if user changes username - "owner" property doesn't change in item model instances created user. gather there ways of syncing data between views/models/controllers, how sync data between different model instances of different models. appreciated, thanks.
here item.client.controller.js
'use strict'; // items controller angular.module('items').controller('itemscontroller', ['$scope','$stateparams', '$location', 'authentication', 'items', function($scope, $stateparams, $location, authentication, items) { $scope.authentication = authentication; $scope.currentpage = 1; $scope.pagesize = 10; $scope.offset = 0; // page changed handler $scope.pagechanged = function() { $scope.offset = ($scope.currentpage - 1) * $scope.pagesize; }; // create new item $scope.create = function() { // create new item object var item = new items ({ name: this.name, description: this.description, owner: $scope.authentication.user.username });
here items.client.services.js 'use strict';
//items service used communicate items rest endpoints angular.module('items').factory('items', ['$resource', function($resource) { return $resource('items/:itemid', { itemid: '@_id' }, { update: { method: 'put' } }); } ]);
and users.client.services.js
'use strict'; // users service used communicating users rest endpoint angular.module('users').factory('users', ['$resource', function($resource) { return $resource('users', {}, { update: { method: 'put' } }); } ]);
Comments
Post a Comment