javascript - Loading one dataset using data from another in Angular $watch -
i creating messaging service needs following 1.) load messsage our messages service, recipient's ids, , load recipients' info users service. i've tried both using messages service callback, , creating watcher on message object, without success. service works, doesn't assign result $scope correctly. here's controller. of services working correctly:
function messagectrl ($scope, $http, $location, $routeparams, messages, members) { if ($routeparams.mid) { // checks id of message in route. otherwise, creates new message. $scope.mid = $routeparams.mid; $scope.message = messages.messages({mid: $scope.mid}).query(); $scope.$watch("message", function (newval, oldval, scope) { if (newval.data) { $scope.recipients = members.members({uids: newval.data[0].uids}).query(); } }, true); } else { $scope.create = true; } // events $scope.save = function () { }; $scope.preview = function () { }; $scope.send = function () { }; }
the correct way use query
perform action in callback passed in query function. in other words$scope.message
should assigned in callback. don't need $watch. can call other service within callback directly. keep clean please use deferred
http://docs.angularjs.org/api/ngresource.$resource
Comments
Post a Comment