2

So I couldn't find my answer anywhere. Using node I got everything from database, and I outputted it into the file. It's simple JSON data, chat logs. I can access it though my browser. Looks like this:

[{
  "id":"1b4f0d8b-4577-493e-adde 68a9a96f647d",
  "message":"Hi",
  "name":"NilmeX",
  "timestamp":"18:11"
},
{
  "id":"4b4f2dc1-7162-484b-98b4-dbdbc751dff4",
  "message":"Hi2",
  "name":"NilmeX",
  "timestamp":"18:11"
}]

Etc..

Now how can I get this data by angular? I tried $http.get but I think I messed something up... I'm new to angular and node, so if someone can explain it to me I will be happy.

6
  • can you post your try with $http.get and we can figure it out Commented Jun 11, 2017 at 20:14
  • @Abdoutelb $http.get("/logs/chat") .then(function(response) { $scope.msgs = response.data; }); Commented Jun 11, 2017 at 20:21
  • This url is invalid , you can try put the working url in the browser if it return the right data put it inside $http.get Commented Jun 11, 2017 at 20:24
  • @Abdoutelb Im getting Cannot read property 'get' of undefined all the time. Weird Commented Jun 11, 2017 at 20:29
  • 1
    @Abdoutelb Oh damn, I was, but only in function... Stupid mistake. Thanks for help! Commented Jun 11, 2017 at 20:36

1 Answer 1

1
<div ng-app="myApp" ng-controller="myCtrl"> 


<p ng-repeat="item in myArray">{{item.id}} - {{item.name}}</p>



</div>

<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope, $http) {
    $http.get("service endpoint from nodejs")
    .then(function(response) {
        $scope.myArray = response.data;
    });
});
</script>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.