I have a mobile app, I have a zone where all the news that ah, and I have option to make the news like what is happening to me and that I can not get the id of the news to send to mysql
I would like to know how can I get the id of the controller that ready the news and use the news id to use the controller that does or like the news.
Controller News List
.controller('ListaNoticiasHome', function($scope, $http, $stateParams, sessionService, $partilharRecursos) {
$http.get("https://www.sabeonde.pt/api/api_noticias_home.php").success(function (data) {
$scope.noticias_home = data;
$partilharRecursos.set('idNoticia', data.id);
});
})
Controller Like
.controller('LikeNoticiasHome', function($scope, $http, $stateParams, sessionService, $partilharRecursos) {
var hasLiked = false;
$scope.like= function (){
if (!hasLiked) {
hasLiked = true;
$scope.liked = 'Não Gosto';
$scope.likeCount += 1;
$http.get("https://www.sabeonde.pt/api/api_like_noticias.php?post_id="+$partilharRecursos.get("idNoticia")+ "&user_id=" + sessionService.get('user_id')).success(function (data) {
$scope.like_noticias_home = data;
});
} else {
hasLiked = false;
$scope.liked = 'Gosto';
$scope.likeCount -= 1;
$http.get("https://www.sabeonde.pt/api/api_unlike_noticias.php?post_id="+$partilharRecursos.get("idNoticia")+ "&user_id=" + sessionService.get('user_id')).success(function (data) {
$scope.like_noticias_home = data;
});
}
}
})
HTML
<div class="row" ng-repeat="noticias in noticias_home">
<div class="col">
<a href="#/app/ver-noticia/{{noticias.url_artigo}}/{{noticias.id}}">
<div style="background: url(https://www.sabeonde.pt/gtm/anexos/posts_home/{{noticias.id_anexo}}.{{noticias.tipo}}); border-top-left-radius:10px; border-top-right-radius:10px; height: 200px; background-size: 100% 100%; background-repeat: no-repeat;">
</div>
</a>
<div style="border-bottom-left-radius:10px; border-bottom-right-radius:10px; height: 100px; background-color: white;">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td colspan="2" valign="top">
<a href="#/app/ver-noticia/{{noticias.url_artigo}}/{{noticias.id}}"><div style="font-size: 15px; color:black; margin:5px 0px 15px 10px; font-weight: bold; ">{{noticias.titulo}}</div></a>
</td>
</tr>
<tr>
<td valign="top">
<div ng-init="liked='Gosto'" ng-click="like()" ng-controller="ListaNoticiasHome" style="margin-left:10px;" class="botao_gosto"><i class="fa fa-heart"></i> {{liked}}</div>
<div id="mostra_gostos" class="mostra_gostos">{{noticias.likes}}</div>
<a href=""><div class="botao_posts"><i class="fa fa-share-alt"></i> Partilhar</div></a>
<a href="#/app/ver-noticia/{{noticias.url_artigo}}/{{noticias.id}}"><div class="botao_posts"><i class="fa fa-search"></i> Ver +</div></a>
</td>
</tr>
</table>
</div>
</div>
</div>