Запуск функции из другого контроллера
Всем привет!
Не получается решить такую задачу.
Есть два контроллера - ProfileController и NotifyController.
notifyController View:
<div ng-controller="notifyController" ng-init="getMsg()">
<ul>
<li ng-repeat="item in myMsg.group">
<a href="#" ng-click="getMsg(item.id)">{{item.name}}</a>
</li>
</ul>
<div ng-repeat="item in myMsg.msg">
{{item.text}}
</div>
</div>
profileController View:
<div ng-controller="profileController">
<button ng-click="getMsg(44)">Написать</button>
</div>
Задача стоит такая: нажав на кнопку "Написать", сервис pmService подгружал в контроллер notify новые данные и отображал их там.
app.factory('pmService', function ($http) {
return {
privateMessages: {
loader: false,
group: {},
data: {}
},
getMsg: function getMsg(id) {
$http.post('/pm/read/' + id, {
readed: privateMessages.loader,
added: privateMessages.data.length > 0
}).success(function (data) {
privateMessages.data = data.msg;
privateMessages.group = data.group;
});
}
};
});
app.controller('profileController',function(pmService){
$scope.getMsg = function(id){
pmService.getMsg(id);
};
});
app.controller('notifyController',function(pmService){
$scope.myMsg = '';
$scope.getMsg = function(id){
pmService.getMsg(id);
$scope.myMsg = pmService.privateMessages();
};
});
Первая проблема - почему-то не отправляется ajax-запрос, вторая - не присваиваются данные myMsg и не отображаются. Третья проблема - не понимаю, что должна делать функция в profileController, чтобы обновлять данные в контроллере notifyController.