1
I have a mobile app, I have an area where I list all the news that ah, and I have an option to like the news what is happening to me and that I am not able to get the news id to send to mysql
I would like to know how I can get the controller id that I list the news and use the news id to use in the controller that tastes the news.
Controller Lista Noticias
.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>
Let’s go continue this discussion in chat.
– César Sousa