Show username responsible for such ID in html

Asked

Viewed 193 times

1

I am making a very basic forum and I have a very easy question, but I am beginner at the angle and it is killing me. When creating a new topic, this topic creates an ID ie each topic has its own. In the Index there is a list of created topics and an access button that leads to a given topic. My doubt is how to show the title, subject and description of the topic accessed on the test page. Note: I am using mongod and Postman for data registration, and the url where the data is http://localhost:3000/topic/list

Below the button and the js

 $scope.AcessarTopico = function(index){
        //$scope.item = $scope.itens[this.id:id];
        alert("o id do cara é - " + $scope.itens[index]._id);
        window.location="file:///C:/Users/Mayla/Desktop/Forum/teste.html?id="+$scope.itens[index]._id;
        $scope.edit = true;
<button class="btn btn-success btn-small" ng-click="AcessarTopico($index)">

1 answer

1

Your role is requesting a new page, and passing the id of the forum in question. In this new page the ideal is to have a controller and in it a method that when starting to search the data of this specific forum. Something something like this:

In the test.html

<div ng-controller="forumList" ng-init="carregarDados()">
 <h2>{{ forum.titulo }}</h2>
 <h4> {{ forum.assunto }}</h4>
</div>

In the angular controller:

var myApp = angular.module('myApp',[]);

myApp.controller('forumList', ['$scope', '$http', function($scope, $http) {

   $scope.carregarDados = function() {
      var url = sua_url;
      $http.get(url, {id: pegue_id_da_pagina).then(
            function successCallback(resposta) {
               $scope.forum = resposta.data.forum;
            },
            function errorCallback(resposta) {
            }
        );
   }
}]);
  • In the test you will have the forum title and subject and description items and each forum has an id.

  • And this data comes from the database

  • The method you showed is directing the application to test.html! In order for it to work, your.html test has to have a controller! And in your initial method have a get that fetches the data from that forum post!

  • I edited the answer

  • In the id part, I just put - var url = 'http://localhost:3000/topic/list' $http.get(url, {id: $Scope. _id}). then( ... it would take something more than that, since in the bd this _id.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.